Local Variable Use (SOLVED)

Hello, I’ve got a small question about the use of local variables. I am trying to make it so that the collection changes only after the player collects a certain amount of points. I have it set up that once this point number is achieved local canenter changes from false to true. Now I just need to execute…

if message_id == hash("collision_response") and canenter = true then
	print("checkpoint")
	msg.post("loader:/go#loader", "level_two")
end

This does not seem to be working. Thanks for the help!

If you want to compare variables you need to use ==.
in your case it possible to write this way:

if message_id == hash("collision_response") and canenter then
...
end

Hmmm, this doesn’t seem to be working. Maybe there is an issue with how I have the rest of my code set up?

57%20AM

Thanks again for your help.

Unfortunately, there is not enough info to help you.
I would recommend you add print(message_id) at line 8, to make sure you receive all the messages you need and with the right message names (“can enter”, “collision_response”). Also, check if your code works without canenter variable.

One more option is to use Debugger and breakpoints, hot help you to understand what did you miss.

On line 17 you declare the variable ‘canenter’ again, remove the local part and it should work.

1 Like

Much thanks! This was the problem, thanks for your help!

Thanks! The issue turned out to be that I redeclared the variable later on in the code, thanks for your help!

1 Like