Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

Quick question involving Strings and (Global) Variables
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Fri Feb 27, 2009 2:49 am    Post subject: Reply with quote

Ah!

First, a tip. This is unreadable:
Code:
set input key (5,17,18)

Write this instead:
Code:
set input key (@BUTTON start,17,18)


Now, your setinputkey script is way longer than it needs to be. You'll notice that in the example I posted I used 1 line per key, you've duplicated a lot of code and used 17! Here's one reason why code duplication is a bad thing: you've made a mistake, and instead of fixing a single line of code you now have to a hundred. However, you can use find-and-replace.

In setinputkey:
Code:
set variable (GVar,17)

GVar is the ID of the global variable holding the scancode, write this instead:
Code:
write global variable (GVar, 17)

or better:
Code:
write global variable (GVar, key:W)


And in getinputkey:
Code:
if (GVar == 18)

should be
Code:
if (read global variable(GVar) == 18)



What I recommend you do is delete setinputkey and replace it with this small script:

Code:
script, Set Input Key, GVar=0, string1=0, string2=1, begin
  variable (i)
  for (i, 0, 147) do (
    if (key is pressed (i)) then (
      set on keypress script (@nokeypress)
      if ((i >= 2 && i <= 54)        #key:1 to key:RIGHTSPACE
          || i == 56 || i == 57      #key:ALT || i == key:SPACE
          || (i >= 71 && i <= 83)    #key:HOME to key:DELETE
          || (i >= 128 && i <= 147)) #joy:BUTTON 1 to joy:Y DOWN
      then (
        # pressed a valid key
        write global variable (GVar, i)
      )
      # if not a valid key: do nothing

      get input key (GVar,string1,string2)

      set tag (tag:CUSTOMIZING,off)

      wait (2)
      set on keypress script (@optionstwokeypressscript)
      exit script
    )
  )
end


I hope I got the key ranges right.
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group