foo is just a variable holding a value which is set to 1 once a condition is reached.
when the sprite is created for the first time, foo is set to 1 to ensure the sprite will not be created again.
If you are using the same variable in multiple functions, you either have to declare the variable as global or pass it to a function with functionname(variable1, variable2...)
I improved the code, should work now:
// Project: Clicker
// Created: 2016-08-16
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Clicker" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
setvsync(0)
global clickbtn, clickdamage, games, autodamage, clickupgrades, clickupgradecose, autoclickupgrades, autoclickupgradecost, foo1, foo2, clkupgrdbtn, autodmg
foo1 = 0
foo2 = 0
games = 1
clickdamage = 1
autodamage = 0
clickupgrades = 0
clickupgradecost = 20
autoclickupgrades = 0
autoclickupgradecost = 50
startTime as float
startTime = timer()
clickbtn = createsprite(loadimage("bluerec.png"))
setspritesize(clickbtn, 100, 30)
setspriteposition(clickbtn, 50, 200)
do
clicked()
upgradeclick()
autoclicker1()
if Timer() > startTime + 1
games = games + autodamage
startTime = timer()
endif
print("Total games " + str(games))
print("Total click damage " + str(clickdamage))
print("Total autodamage " + str(autodamage))
print("Total autoclickupgradecost " + str(autoclickupgradecost))
print("Total autoclick upgrades " + str(autoclickupgrades))
print(screenFPS())
Sync()
loop
function clicked()
if getpointerpressed() = 0
if getspritehittest(clickbtn, getpointerx(), getpointery()) = 1 and GetRawMouseLeftPressed() = 1
games = games + clickdamage
endif
endif
endfunction
function upgradeclick()
if games >= 5
if foo1=0
foo1=1
clkupgrdbtn = createsprite(loadimage("redrec.png"))
setspritesize(clkupgrdbtn, 100, 30)
setspriteposition(clkupgrdbtn, 50, 300)
endif
if getpointerpressed() = 0
if getspritehittest(clkupgrdbtn, getpointerx(), getpointery()) = 1 and GetRawMouseLeftPressed() = 1
if games >= clickupgradecost
games = games - clickupgradecost
clickupgradecost = (clickupgradecost + clickupgrades) * 1.15
clickdamage = clickdamage + 1
clickupgrades = clickupgrades + 1
endif
endif
endif
endif
endfunction
function autoclicker1()
if games >= 50
if foo2=0
foo2=1
autodmg = createsprite(loadimage("yellowrec.png"))
setspritesize(autodmg, 100, 30)
setspriteposition(autodmg, 50, 400)
endif
if getpointerpressed() = 0
if getspritehittest(autodmg, getpointerx(), getpointery()) = 1 and GetRawMouseLeftPressed() = 1
if games >= autoclickupgradecost
games = games - autoclickupgradecost
autoclickupgradecost = (autoclickupgrades + autoclickupgradecost) * 1.15
autoclickupgrades = autoclickupgrades + 1
autodamage = autodamage + 1
endif
endif
endif
endif
endfunction
(edit) fixed a bug