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!
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.
//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
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.
//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