Author Topic: Map Editing Script  (Read 3687 times)

sam

  • Fanatic
  • ***
  • Posts: 303
  • This statement is false.
    • MSN Messenger - samlancashire@hotmail.com
    • View Profile
    • samlancashire.com
    • Email
Map Editing Script
« on: 2006-04-08, 06:27:56 PM »
Hey, I'm changing the map editing script a bit and need some help.
I'm completely new to writing script on my own and am guessing the answer to this will be extremely simple.
Here's the part of the code I am changing:
Code: [Select]
   If KeyAscii= Asc ("t") Then
      MpEd.EditMode=1
   elseif MpEd.EditMode=1 then
   MpEd.EditMode=0
   end if
I want it so that instead of pushing "t" you push "space". I know the asc # (or whatever it's called) for "space" is 32. Can someone help?

sam

  • Fanatic
  • ***
  • Posts: 303
  • This statement is false.
    • MSN Messenger - samlancashire@hotmail.com
    • View Profile
    • samlancashire.com
    • Email
Re: Map Editing Script
« Reply #1 on: 2006-04-08, 08:29:49 PM »
I tried this but it just works for every key.

Code: [Select]
   If KeyAscii <> 13 Then
      MpEd.EditMode=1
   elseif MpEd.EditMode=1 then
   MpEd.EditMode=0
   end if

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Map Editing Script
« Reply #2 on: 2006-04-08, 09:56:21 PM »
That code will make it happen for every key except a Carriage Return (Asc Char 13 -- i.e. The Enter key)

Basically asc("t") returns the ascii value of the letter "t".  Given any single-character string (string of length one) asc(string) will return the ascii value of that character.  Handily enough, that is what you are given when OnKeyPress is called.  So you are comparing the given value to what you want it to be.  That is, you are checking to see if Keyascii = asc("t").  This equates to checking if KeyAscii = 116 (116 is the ascii value of "t").  So if you want to check to see if they are pressing the spacebar, you could do one of two things:

If KeyAscii = asc(" ") then

or

If KeyAscii = 32 then

I would go with the second one.  The reason that the code uses asc("t") is because it makes it easier for the programmer to understand what is being checked for (i.e. if the "T" key is being pressed).  Most programmers don't have the ASCII chart memorized, but many do know the ascii value for common characters like Space, Carriage Return, and Double Quote (34).  Some also know A is 65, but another level of indirection is sometimes just easier than counting from A to whatever letter you're using.

I hope that helps.
Edward Dassmesser

sam

  • Fanatic
  • ***
  • Posts: 303
  • This statement is false.
    • MSN Messenger - samlancashire@hotmail.com
    • View Profile
    • samlancashire.com
    • Email
Re: Map Editing Script
« Reply #3 on: 2006-04-09, 12:52:51 PM »
It works now, thanks, I thought about just putting a space between the quotation marks but figured it wouldn't work so I never tried.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Map Editing Script
« Reply #4 on: 2006-04-09, 12:56:49 PM »
If you ever want to see if something works, the nice thing about computers is that they rarely blow up when running a VBS file.  Just try it!
Edward Dassmesser

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Map Editing Script
« Reply #5 on: 2006-04-09, 09:39:55 PM »
I guess that depends on your definition of "blow up".