Help with variables

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
Peacfulrvr
Posts: 34
Joined: Mon Nov 03, 2014 7:11 pm

Help with variables

Post by Peacfulrvr » Fri Mar 13, 2015 3:26 pm

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

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Help with variables

Post by magice » Fri Mar 13, 2015 3:52 pm

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.

Klaus
Posts: 11207
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Help with variables

Post by Klaus » Fri Mar 13, 2015 3:56 pm

Yep, and do yourself a favour and ALWAYS put quotes around names/strings!
...
hide image "phonestorebutton.gif"
hide image "startbutton.png"
...

Peacfulrvr
Posts: 34
Joined: Mon Nov 03, 2014 7:11 pm

Re: Help with variables

Post by Peacfulrvr » Fri Mar 13, 2015 4:57 pm

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.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6179
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Help with variables

Post by dunbarx » Fri Mar 13, 2015 5:18 pm

@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

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Help with variables

Post by magice » Fri Mar 13, 2015 5:32 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6179
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Help with variables

Post by dunbarx » Fri Mar 13, 2015 7:01 pm

Magice.

Right you are.

Craig

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Help with variables

Post by magice » Fri Mar 13, 2015 7:32 pm

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"

Peacfulrvr
Posts: 34
Joined: Mon Nov 03, 2014 7:11 pm

Re: Help with variables

Post by Peacfulrvr » Wed Mar 18, 2015 1:03 am

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.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”