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

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Problem with function LevelDraw()
« on: December 31, 2010, 09: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: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Problem with function LevelDraw()
« Reply #1 on: December 31, 2010, 05:05:47 PM »
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: 14
  • Posts: 1,035
Re: Problem with function LevelDraw()
« Reply #2 on: January 01, 2011, 03:34:14 AM »
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: 4
  • Posts: 1,809
Re: Problem with function LevelDraw()
« Reply #3 on: January 01, 2011, 06:09:46 AM »
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..