Help with variables
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 34
- Joined: Mon Nov 03, 2014 7:11 pm
Help with variables
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
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
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
Yep, and do yourself a favour and ALWAYS put quotes around names/strings!
...
hide image "phonestorebutton.gif"
hide image "startbutton.png"
...
...
hide image "phonestorebutton.gif"
hide image "startbutton.png"
...
-
- Posts: 34
- Joined: Mon Nov 03, 2014 7:11 pm
Re: Help with variables
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.
-
- VIP Livecode Opensource Backer
- Posts: 9579
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Help with variables
@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
@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
I see were he has written gStartarrow, but it does not say global in front of itdunbarx 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
-
- VIP Livecode Opensource Backer
- Posts: 9579
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Help with variables
Magice.
Right you are.
Craig
Right you are.
Craig
Re: Help with variables
why not do away with the global variable altogether and use a custom property?
then to make the change
and of course in the if statement:
another thing that bothers me is the wait command. it would be much more efficient for the processor to do this:
Code: Select all
on openStack
set the cStartArrow of this stack to false
end openStack
Code: Select all
set the cStartArrow of this stack to true
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"
-
- Posts: 34
- Joined: Mon Nov 03, 2014 7:11 pm
Re: Help with variables
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.