Page 1 of 1
					
				Help with variables
				Posted: Fri Mar 13, 2015 3:26 pm
				by Peacfulrvr
				I have been here off and on for several months now.  I am working on a program and have been stuck on one problem for 3 or 4 months now.  I have a screen with a start button and arrow buttons for navigation.  I dont want the arrow buttons to move until after the start button has been clicked.  I have tried so many different variations of if-then statements on both obj scripts and the card script and cant get it to work.  Any direction on how I should be setting this up will be appreciated.
On the card script I declare a global gStartarrow and on preopencard I put false in it
Start button obj script
global gAddmoney
global gStartArrow
local sMovePhone
on mouseup
   hide image phonestorebutton.gif
   hide image startbutton.png
   put true into gAddmoney
   put true into sMovePhone
   #putting true into the variable and check on it in the arrow script
   put true into gStartArrow
   wait 1 seconds
   moveobj
end mouseup
gStartarrow
on mouseup
   if gStartArrow is true then 
      movephone "left"  
      end if 
end mouseup
			 
			
					
				Re: Help with variables
				Posted: Fri Mar 13, 2015 3:52 pm
				by magice
				Assuming that these scripts are in two different buttons, and that they are posted exactly as they are written, then you have not declared your variable global in the second script. A global variable must be declared in every script that will access it.
			 
			
					
				Re: Help with variables
				Posted: Fri Mar 13, 2015 3:56 pm
				by Klaus
				Yep, and do yourself a favour and ALWAYS put quotes around names/strings!
...
hide image "phonestorebutton.gif"
hide image "startbutton.png"
...
			 
			
					
				Re: Help with variables
				Posted: Fri Mar 13, 2015 4:57 pm
				by Peacfulrvr
				Thanks I will clean those items up and see if that helps.  I did have the global declared on both previously and it still didn't work.  I will try again.
			 
			
					
				Re: Help with variables
				Posted: Fri Mar 13, 2015 5:18 pm
				by dunbarx
				@Magice, I do not see the broken global reference in the button handlers. "gStartArrow" is declared in both. The other globals are not declared, but they are not involved either. I assume it is declared in the card script. (?)
@Peacfulrvr.  And do everyone a favor. Place all your script examples within the "code" tags. It makes it much easier to see the structure of handlers.
Craig Newman
			 
			
					
				Re: Help with variables
				Posted: Fri Mar 13, 2015 5:32 pm
				by magice
				dunbarx wrote:@Magice, I do not see the broken global reference in the button handlers. "gStartArrow" is declared in both. The other globals are not declared, but they are not involved either. I assume it is declared in the card script. (?)
@Peacfulrvr.  And do everyone a favor. Place all your script examples within the "code" tags. It makes it much easier to see the structure of handlers.
Craig Newman
I see were he has written gStartarrow, but it does not say global in front of it
 
			
					
				Re: Help with variables
				Posted: Fri Mar 13, 2015 7:01 pm
				by dunbarx
				Magice.
Right you are. 
Craig
			 
			
					
				Re: Help with variables
				Posted: Fri Mar 13, 2015 7:32 pm
				by magice
				why not do away with the global variable altogether and use a custom property?
Code: Select all
on openStack
set the cStartArrow of this stack to false
end openStack
then to make the change
Code: Select all
set the cStartArrow of this stack to true
and of course in the if statement:
Code: Select all
if the cStartArrow of this stack is true
another thing that bothers me is the wait command. it would be much more efficient for the processor to do this:
Code: Select all
send moveobj to me in 1 second  --if the moveobj handler is somewhere other than this script then send it there instead of to "me"
 
			
					
				Re: Help with variables
				Posted: Wed Mar 18, 2015 1:03 am
				by Peacfulrvr
				Thanks all for the help.  I will have to take your suggestions and see how to use them in my game.   Until then I cheated a bit... i put decoy images over the arrows and when the start button is hit those images are hid and the actual arrow navigation buttons are displayed and active.