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: FourthWorld, heatherlaine, Klaus, kevinmiller
-
InLacyWeTrust
- Posts: 5
- Joined: Tue Nov 19, 2013 3:09 am
Post
by InLacyWeTrust » Tue Dec 03, 2013 5:05 am
I have a 2 water tanks with seven buttons on them ranging 1-7, When the user clicks a button, the button and all those below it will turn blue. I have declared the global variables
tank1Level and
tank2Level on each button and on the stank. Here is the code I have for one of the buttons.
Code: Select all
//Height of individual tank
global tank2Level
//Shared variable for height of tank level to determine tank visual
global tankLevel
on mouseDown
put 2 into tankLevel
put 2 into tank2Level
send "setTank1" to this stack
end mouseDown
once the user is satisfied with the water level they can "fire" the tanks by clicking a button, here is the code for that
Code: Select all
global tank1Level, tank2Level
global tankLevel
global tankHeight
on mouseUp
put tank1Level + tank2Level into tankHeight
send fire to this stack
end mouseUp
***When I run this code, tank1Level, tank2Level, and tannHeight are not storing their values when control switched to the stack. Am I using these variables incorrectly? If the stack script would be helpful please let me know!

Last edited by
InLacyWeTrust on Tue Dec 03, 2013 5:55 am, edited 2 times in total.
-
Simon
- VIP Livecode Opensource Backer

- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
Post
by Simon » Tue Dec 03, 2013 5:25 am
Do you have
global tank1Level, tank2Level
global tankLevel
global tankHeight
in your stack script?
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
InLacyWeTrust
- Posts: 5
- Joined: Tue Nov 19, 2013 3:09 am
Post
by InLacyWeTrust » Tue Dec 03, 2013 5:53 am
yes here it is
Code: Select all
//Monster Game
//
//by: Adam
//Height of Water tanks
global tankHeight
//Height of individual tanks
global tank1Level, tank2Level
//Shared variable for height of tank level to determine tank visual
global tankLevel
//setTank sets the visible representation of
//a water level in tank 1 defined by the user
on setTank
switch tankLevel
case "1"
set the visible of grc "t1_1" to false
set the visible of grc "t1_2" to true
set the visible of grc "t1_3" to true
set the visible of grc "t1_4" to true
set the visible of grc "t1_5" to true
set the visible of grc "t1_6" to true
set the visible of grc "t1_7" to true
break
case "2"
set the visible of grc "t1_1" to false
set the visible of grc "t1_2" to false
set the visible of grc "t1_3" to true
set the visible of grc "t1_4" to true
set the visible of grc "t1_5" to true
set the visible of grc "t1_6" to true
set the visible of grc "t1_7" to true
break
case "3"
set the visible of grc "t1_1" to false
set the visible of grc "t1_2" to false
set the visible of grc "t1_3" to false
set the visible of grc "t1_4" to true
set the visible of grc "t1_5" to true
set the visible of grc "t1_6" to true
set the visible of grc "t1_7" to true
break
case "4"
set the visible of grc "t1_1" to false
set the visible of grc "t1_2" to false
set the visible of grc "t1_3" to false
set the visible of grc "t1_4" to false
set the visible of grc "t1_5" to true
set the visible of grc "t1_6" to true
set the visible of grc "t1_7" to true
break
case "5"set the visible of grc "t1_1" to false
set the visible of grc "t1_2" to false
set the visible of grc "t1_3" to false
set the visible of grc "t1_4" to false
set the visible of grc "t1_5" to false
set the visible of grc "t1_6" to true
set the visible of grc "t1_7" to true
break
case "6"set the visible of grc "t1_1" to false
set the visible of grc "t1_2" to false
set the visible of grc "t1_3" to false
set the visible of grc "t1_4" to false
set the visible of grc "t1_5" to false
set the visible of grc "t1_6" to false
set the visible of grc "t1_7" to true
break
case "7" set the visible of grc "t1_1" to false
set the visible of grc "t1_2" to false
set the visible of grc "t1_3" to false
set the visible of grc "t1_4" to false
set the visible of grc "t1_5" to false
set the visible of grc "t1_6" to false
set the visible of grc "t1_7" to false
break
default
beep
end switch
set the visible of button "fire" to true
put 0 into tankLevel
end setTank
//setTank1 sets the visible representation of
//a water level in tank 2 defined by the user
on setTank1
switch tankLevel
case "1"
set the visible of grc "t2_1" to false
set the visible of grc "t2_2" to true
set the visible of grc "t2_3" to true
set the visible of grc "t2_4" to true
set the visible of grc "t2_5" to true
set the visible of grc "t2_6" to true
set the visible of grc "t2_7" to true
break
case "2"
set the visible of grc "t2_1" to false
set the visible of grc "t2_2" to false
set the visible of grc "t2_3" to true
set the visible of grc "t2_4" to true
set the visible of grc "t2_5" to true
set the visible of grc "t2_6" to true
set the visible of grc "t2_7" to true
break
case "3"
set the visible of grc "t2_1" to false
set the visible of grc "t2_2" to false
set the visible of grc "t2_3" to false
set the visible of grc "t2_4" to true
set the visible of grc "t2_5" to true
set the visible of grc "t2_6" to true
set the visible of grc "t2_7" to true
break
case "4"
set the visible of grc "t2_1" to false
set the visible of grc "t2_2" to false
set the visible of grc "t2_3" to false
set the visible of grc "t2_4" to false
set the visible of grc "t2_5" to true
set the visible of grc "t2_6" to true
set the visible of grc "t2_7" to true
break
case "5"set the visible of grc "t2_1" to false
set the visible of grc "t2_2" to false
set the visible of grc "t2_3" to false
set the visible of grc "t2_4" to false
set the visible of grc "t2_5" to false
set the visible of grc "t2_6" to true
set the visible of grc "t2_7" to true
break
case "6"set the visible of grc "t2_1" to false
set the visible of grc "t2_2" to false
set the visible of grc "t2_3" to false
set the visible of grc "t2_4" to false
set the visible of grc "t2_5" to false
set the visible of grc "t2_6" to false
set the visible of grc "t2_7" to true
break
case "7" set the visible of grc "t2_1" to false
set the visible of grc "t2_2" to false
set the visible of grc "t2_3" to false
set the visible of grc "t2_4" to false
set the visible of grc "t2_5" to false
set the visible of grc "t2_6" to false
set the visible of grc "t2_7" to false
break
default
beep
end switch
set the visible of button "fire" to true
put 0 into tankLevel
end setTank1
on fire
switch tankLevel
case "0"
set the visible of grc "water1" to true
set the visible of the image "sp1" to true
break
default
beep
end switch
end fire
//Not Yet implemented...
on readLevel
switch tankLevel
case "1"
break
case "2"
put 2 into tankLevel
break
case "3"
break
case "4"
break
case "5"
break
case "6"
break
case "7"
break
default
beep
end switch
put 0 into tankLevel
end readLevel
-
Simon
- VIP Livecode Opensource Backer

- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
Post
by Simon » Tue Dec 03, 2013 6:06 am
Just using 2 buttons and your scripts the globals are working.
Not sure when tank1Level is used, but that doesn't matter.
Have you been dropping breakpoints in your code?
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
InLacyWeTrust
- Posts: 5
- Joined: Tue Nov 19, 2013 3:09 am
Post
by InLacyWeTrust » Tue Dec 03, 2013 6:18 am
Hey Simon,
I really appreciate you running my code

Turns out the problem was a miss-spelled variable on a few "tank" buttons.
Darn sleep deprived eyes
Thanks!