Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check to see if function was called?

Tags:

swift

How would i go about checking if a function was called? I have created a function to see if the level was completed like so:

func levelOneCompleted(){

}

When the level one is beat, i call the function levelOneCompleted().

The scene then goes to another scene. It's at this scene that i want to check if the function was called. I am thinking i can make some kind of "if statement".

if levelOneCompleted is called {
//do this

else{

//do this
}

What would be the best way of going about this?

like image 253
Matt Cantrelle Avatar asked Feb 05 '23 09:02

Matt Cantrelle


1 Answers

Set a boolean flag to true inside levelOneCompleted():

var isLevelOneCompleted = false

func levelOneCompleted(){
    // do things...
    isLevelOneCompleted = true
}

And later...

if isLevelOneCompleted {
    //do this
} else {
    //do this
}
like image 89
Paolo Avatar answered Feb 06 '23 21:02

Paolo