Function.ReturnValue forgets my previously picked objects when I try to update them?

0 favourites
From the Asset Store
Fantasy Game includes more than 600 sound effects inspired by hit computer games like World of Warcraft and Diablo.
  • I have a function I run to check if the player has a skill when it would be triggered. This has worked perfectly fine for the implementation of 40+ other skills, but this one time it just refuses to work properly. In this case, the skill is supposed to heal the player slightly when the conditions are met to pick up a coin:

    So as you can see, "PlayerSkillSetup" is ran, and if the player has the skill it is checking for ("skill_greed1") the Function.ReturnValue should equal "skillExists", at which point it runs the highlighted code.

    And it does run that code, but on nothing. Because despite passing the PlayerFamily.UID through the "PlayerSkillSetup" function and verifying it is picking the correct instance, the highlighted code runs on nothing. It spawns the ValueText object at 0,0, so it is running.

    I have tried a dozen different work arounds on this thing to no avail, and I cannot see what very well may be an obvious issue, help would be greatly appreciated!

  • This looks quite old to me so it's Construct 2 yeah? What UID is it showing in the browser logging? It may forget picked instances if it runs that condition next tick but looks like Construct 2.

  • This is Construct 3, but it is built on a project that was originally started in Construct 2, and had far too many old Functions for me to feel comfortable updating them to the new Function system. I've continued to use the old function system as a result.

    What UID is it showing in the browser logging?

    This is the frustrating part of this issue. If disable the actions that update the players health and spawn the text object, the browser alert returns the correct UID:

    However, the moment I toggle those actions back on, the Browser alert returns a UID of 0.

  • That's odd. If you say that it works that way, maybe try to insert a browser log of the UID in between each of those actions and see which one is interfering?

  • try to insert a browser log of the UID in between each of those actions and see which one is interfering?

    This was a good idea, but gives me... bizarre results.

    If I set it up like this, where the browser alert comes after everything else and I disable the ValueText object spawn, it returns the correct UID:

    However, it fails to actually update the players variables. Their HP remains the same (double checked in the debugger to be sure).

    Enabling the ValueText object spawn causes the browser alert to once again return 0.

  • The skill set up function does what? Check an instance variable on the player? I would skip using functions here and just use a condition, player has skill.

  • Skills aren't tracked through instance variables, there are far too many of them to do that.

    The PlayerSkillSetup function scans an array that is populated with the collected skills of the player(s) for the requested skill. If the skill exists in the players Y rows (each player has their own X row) then the function returns the "skillExists".

    This system has worked fine for the previous 40+ skills I have setup this way, hence why I haven't bothered sharing the PlayerSkillSetup function since it's never given me these issues with those previous setups.

  • Probably you are not picking instances with the other events but we can't see them. If you change variables only then it will be fine. If it forgets the picked instances then it must be down to the condition which is from Construct 2, not really worth breaking down why that does or doesn't work as it's difficult/impossible to recreate.

    You should use the Construct 3 functions, or potentially as a workaround store the UID of the instance in a local variable amongst your other local variables that means at least you don't have to rely on picking from the event which is running every tick. If you have saved the instance in question as a local variable then nothing can really go wrong.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I have never used Function.ReturnValue like that. I always thought it can only be used inside the function.

    Try this condition instead:

    Function.Call("PlayerSkillSetup", PlayerFamily.UID, "skill_greed1")="skillExists"

    Also, make sure there are no "Waits" inside the function.

  • Yes Waits inside the function makes sense, that's probably why the picking is broken. Didn't share the functions though.

  • Storing the local UID and referring to it again after the Function.ReturnValue did the trick, thanks for suggesting that. I had tried using that method previously, but I think I was a little hasty in dismissing it and placed the "Set LocalUID" action in the wrong spot, or needed to use the "Pick All" event as well, in any case it's working properly now:

    Why this is the only time this function has failed to produce results is beyond me, if it happens again I might pursue it further but given how many skills I've successfully implemented until now with it, I think I'll leave it be.

  • I think I know what may be the problem. Does this happen with PlayerFamily instance that has IsSwim=false?

  • It was, most PlayerFamily objects are not swimming, and I actually never tested the issue with one that was swimming.

    IsSwim is just a boolean that gets set the moment a player enters water, and then it gets updated to false when the player leaves the water.

  • Also, just saw your previous posts dop2000, there are no waits in any of the functions being used here. There are no waits in any functions in this project for that matter, unless I very specifically needed them and used them knowing picking was unnecessary from that point onward.

  • It was, most PlayerFamily objects are not swimming, and I actually never tested the issue with one that was swimming.

    You may be hitting the old issue with OR-blocks:

    if IsSwim=false and other conditions are true, the event runs, but with zero family instances picked. PlayerFamily.UID in this case will return 0.

    This would explain why you were able to fix your code by adding "Pick All".

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