This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
tball146's profile picture

Variable Help

Started by tball146, 16 September 2015 - 10:22 AM
tball146 #1
Posted 16 September 2015 - 12:22 PM
so i would love to make a game/program but Variables are my biggest issue
so lets say this
loval Vac = 0
if vac == 1 then
print("BANNED")
else
print("hi")
end
ok now the code looks fine but lets say i wanted to change the variable an have it save so lets say i wanted to say banned an save
but i want to be able to have a command like unban then change the variable then reboot an save my changes
can a pro/person who know how tell me how to do this
KingofGamesYami #2
Posted 16 September 2015 - 04:59 PM
If you want a variable to persist you have to use a file. Check out the fs API.
Exerro #3
Posted 16 September 2015 - 05:03 PM
Firstly, variables are case sensitive. That code wouldn't work because you define "Vac" and try to use "vac".

From what I can tell, you want to repeat something and modify the variable each time? Take a look at loops and variables. Rebooting a computer every time a state change occurs is ludicrous.

However, if for whatever reason you do need to reboot, you'll want to save the variable to a file then load it back again. A combination of the FS API, textutils.serialize(), and textutils.unserialize() will allow you to do this.