Jump to content




Variable Help


  • You cannot reply to this topic
2 replies to this topic

#1 tball146

  • Members
  • 20 posts

Posted 16 September 2015 - 11:22 AM

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

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 16 September 2015 - 03:59 PM

If you want a variable to persist you have to use a file. Check out the fs API.

#3 Exerro

  • Members
  • 801 posts

Posted 16 September 2015 - 04: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.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users