Toggling a variable on a timer

Good day all!

I’m just getting into pulp and learning the ropes with a little project. Most things are vaguely similar to languages I’ve dabbled in before but there is one thing that I’m hitting a wall on. I want to have a variable cycle between two values every second. 0, then 1 ,then 0, then 1 etc

It seems like the WAIT function and the LOOP event are where I need to be tinkering but I’ve hit a wall.

on load do
aaa=0
end

on loop do
wait 1 then
if aaa==0 then
aaa = 1
else
aaa = 0
end
end
end

Am I along the right lines here or barking up completely the wrong tree?

Solved it! had the WAIT functions in the wrong place:

on loop do
if aaa==0 then
wait 1 then
aaa = 1
end
else
wait 1 then
aaa = 0
end
end
end

Might I recommend a different way of doing this? The thing is, when you use wait, the rest of your loop function can’t do anything else. Also, it’s generally best to have things based on the number of frames instead of time.

on loop do
  loop_counter += 1
  if loop_counter > 19 then
    aaa += 1
    if aaa>1 then
      aaa = 0
    end
    loop_counter = 0
  end
  // and then you can put the rest of the things you want to happen in the loop here
end

or if you really want it to be time based:

on loop do
  next_timestamp = datetime.second
  if next_timestamp != last_timestamp then
    last_timestamp = next_timestamp
    aaa += 1
    if aaa>1 then
      aaa = 0
    end
  end
  // the rest of your game loop would go here
end