Author Topic: Problem with function LevelDraw()  (Read 789 times)

0 Members and 1 Guest are viewing this topic.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Problem with function LevelDraw()
« on: December 31, 2010, 01:31:47 AM »
Hello,

When I declare a variable in my function LevelDraw(), and run the level, it works fine.
But then, if I quit and reload the level, all the variables that were learned from the previous time I played are still there!

This is a problem because it stops new things being procedurally generated.  When the level loads, I want to say "if init == nil then" run a whole bunch of math.randoms to procedurally generate stuff, as well as setting "init" to = 1.  That way the code should only be run once.  But when I do this inside a LevelDraw, it remembers the values of all variables between plays.  :/


This is hard problem to explain..  :P

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 17
  • Posts: 904
  • Eufloria: Yes
Re: Problem with function LevelDraw()
« Reply #1 on: December 31, 2010, 09:05:47 AM »
Stick something like

if (Quit(true) or Quit(false)) then
init = nil
end

in your LevelLogic. That code probably won't work, but I hope it explains what I mean. Basically, check if the level is quit, then reset init.

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 13
  • Posts: 1,035
Re: Problem with function LevelDraw()
« Reply #2 on: December 31, 2010, 07:34:14 PM »
Currently unsure if just putting "all your variables = nil" at the end of your level logic function will work (execution may be interrupted after a call to Quit()) but if so then in future I will add LevelShutdown

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Problem with function LevelDraw()
« Reply #3 on: December 31, 2010, 10:09:46 PM »
I found a workaround to this. Somewhat obvious, but basically I just declare all my variables in LevelSetup instead.  That works fine, so no need to worry about this really..