Local variables in recursive functions across multiple objs?

0 favourites
  • 7 posts
From the Asset Store
"Easy Local Notifications" enhances games with customizable local notifications.
  • Do local (non-static, non constant) recursive function variables get overwritten when another object calls that same function?

    To put it another way, I have an object type that I want to perform a given function over and over again until a set point but whenever another instance of that object type calls that function, the first object stops its recursion.

    I've attached a screenshot and my capx to show the specific problem I'm having.

    [attachment=0:1k3nx9zt][/attachment:1k3nx9zt]

    [attachment=1:1k3nx9zt][/attachment:1k3nx9zt]

    Thanks!

  • Hi

    If you read here: https://www.scirra.com/manual/149/function

    You can see there are under: "Advanced function features"

    "Note that functions calling other functions or recursing create a new "stack" of local variables. In other words, like in programming languages, local variables are unique at each level of function call. This does not apply to static local variables or global variables."

    Anyway, got a question, how do i add functions to my game ? O.o Can't find it anywhere.

  • Hi

    If you read here: https://www.scirra.com/manual/149/function

    You can see there are under: "Advanced function features"

    "Note that functions calling other functions or recursing create a new "stack" of local variables. In other words, like in programming languages, local variables are unique at each level of function call. This does not apply to static local variables or global variables."

    Anyway, got a question, how do i add functions to my game ? O.o Can't find it anywhere.

    Add the Function plugin

    Add an event and choose Function -> On Function

    Type function name in quotes

  • > Hi

    >

    > If you read here: https://www.scirra.com/manual/149/function

    >

    > You can see there are under: "Advanced function features"

    > "Note that functions calling other functions or recursing create a new "stack" of local variables. In other words, like in programming languages, local variables are unique at each level of function call. This does not apply to static local variables or global variables."

    >

    > Anyway, got a question, how do i add functions to my game ? O.o Can't find it anywhere.

    >

    Add the Function plugin

    Add an event and choose Function -> On Function

    Type function name in quotes

    codah

    Could you be a nice guy to provide a link for downloading it ? ^^

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It's a standard plug-in within Construct 2, it's an Object you have to make in your Layout mode. Then, you can use it in your Event with a call.

  • Edit: what inquiesco said

    Right click on Object types (under Projects) and choose Insert new object

    Double click 'Function'

    Click on "Add event" in the event sheet

    Double click on Function

    Double click on "On function"

    Type MyFunction between the quotes and click Done

    You now have a function called "MyFunction"

    To add code to it:

    Click on "Add Action" on the event sheet next to Function | On "MyFunction"

    Add any normal actions

    You can also add sub events under the "Function | On "MyFunction" event

  • Thanks for the reply but I've read the documentation and what it explains seem to contradict the behavior in my project.

    According to the documentation, my function's variables (the Solder IDs) should be unique to each time the function is run. However, when the project is run, the variables are overwritten by more recent calls of the function.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)