What codes do i use to make it so if score = 50 then it will change scene to level2.lua? [import]uid: 132369 topic_id: 25369 reply_id: 325369[/import]
You’ll wanna do this:
[lua]
local function checkScore()
if score == 50 then
director:changeScene(“level2”)
end
end[/lua]
You will then want to either apply a timer, to trigger and check the score. Or apply an event listener to Runtime.
This isn’t tested but it should work.
Hope this helps
Ollie [import]uid: 67534 topic_id: 25369 reply_id: 102458[/import]
Ollie’s code assumes you are using Director, which I imagine you are - but it would be useful in the future to specify in your post
[import]uid: 52491 topic_id: 25369 reply_id: 102508[/import]
Just a little more info for you and a word of warning.
If you use something like
if score == 50 then
You are opening yourself up to a world of opportunities for that if block to be missed/not evaluate to true. For instance, the user scores 50 then say less than a second later scores again, so his score is now say 52 or 60, there is a chance that the if statement won’t have had time to evaluate during that time and now the statement will never evaluate to true as it no longer would be, and your code in that block will not execute.
You really need to allow for these scenarios…
So instead, this check will ensure the above scenario doesn’t cause you any grief:
if score \>= 50 then
that checks if the score is more than or equal to 50, so if the user has exactly 50 as his score fine, however if between him scoring 50 and the if statement running he scores another 10, then there is no issue, as the code is flexible enough to check for that possibility [import]uid: 84637 topic_id: 25369 reply_id: 102738[/import]