Solo Lua to print the current tick upon level completion?

Have a question, suggestion, or comment about Aleph One's features and functionality (Lua, MML, the engine itself, etc)? Post such topics here.

Solo Lua to print the current tick upon level completion?

Post Mar 23rd '16, 23:19

I'm trying to put together a small script to (for now) print to console Game.ticks whenever a level is completed. this is what i have currently (after stripping it down a bit):

Code: Select all
Triggers = {}

function Triggers.cleanup()
   if Level.completed == true then
      Players.print(Game.ticks)
   end
end

however, this seems to not be working. Manually typing in Players.print(Game.ticks) does display the current tick in the top left, though. Is there something I'm missing?
2Tie

Post Mar 23rd '16, 23:50

When you say "completed," do you mean "when all mission objectives are complete" or do you mean "when the player exits the level?" Because the trigger you chose fires during the latter time frame. This means you'll probably never see the message, because the level will end.

You might want something like this:

Code: Select all
levelWasComplete = false

Triggers = {}

function Triggers.idle()
   if Level.completed then -- boolean values don't need == comparisons
      -- check to see if we already knew it was complete
      if not levelWasComplete then
    -- if not, print
    Players.print(Game.ticks)
      end
      -- this makes sure the print statement only happens once
      levelWasComplete = true
   end
end



I don't really have a good, quick test for this, so I can't guarantee that it works. The main thing is that you've got the wrong trigger.
User avatar

irons
(.Y.)

Post Mar 24th '16, 00:58

It was indeed the latter situation, I didn't know the console output got wiped at the end of each level. Trying a different approach then, since i know the ticks doesn't reset between levels:

Code: Select all
Triggers = {}

function Triggers.init(r)
   if Level.index ~= 0 then
      Players.print(Game.ticks)
   end
end


though this is similarly not working. Putting "Players.print(Game.ticks)" alone in Triggers.idle() works, so i know the file's being read through by the game...
2Tie

Post Mar 24th '16, 01:37

init has the same problem. This makes it hard to debug errors that occur at init, and I hate it. You can try something not unlike what I posted: have a variable initially set to false, check if it's still false in idle, print if false, and set it to true after the check. It should thus only be true for the first tick. I have used this method to track down problems/unexpected values/etc. The print output will actually display.
User avatar

irons
(.Y.)

Post Mar 24th '16, 12:36

Don't even need a variable

Code: Select all
Triggers = {}

Triggers.idle = function()
  Players.print(Game.ticks)
  Triggers.idle = nil
end
User avatar

treellama
Pittsburgh

Post Mar 24th '16, 17:54

why get rid of idle dude i need that
User avatar

irons
(.Y.)

Post Mar 24th '16, 20:03

just assign idle back to a valid function in every other trigger then set it back to nil when idle is called that way you will have idle some of the time

compromise
User avatar

Wrkncacnter

Post Mar 24th '16, 22:00

why isn't this a poll
User avatar

irons
(.Y.)

Post Mar 25th '16, 01:51

dude, seriously
User avatar

treellama
Pittsburgh


Return to Aleph One Discussion



Who is online

Users browsing this forum: No registered users