Forum rules - please read before posting.

Custom Action's Issue: All custom actions run twice.

edited July 2016 in Technical Q&A
Hi, everyone. I'm having a weird issue.

Basically, all my custom actions are being called twice by AC, even though I'm not using any kind of loops in the run() function (or anywhere else for that matter). I'm also making sure to not have any duplicated actions in my Action lists, so I'm pretty sure that's not the issue. 

I first noticed the problem when I tested an Action I made to recover my character's HP/MP or whatever, and I noticed when I used an Item I was getting the wrong amounts. I quickly saw I was getting double of what I was telling the action to restore, so I went and double checked all the scripts the action depended on, but I found nothing wrong, so instead I added Debug.Logs in my AC custom action. And sure enough the Debug.Logs returned twice in the console. Then, to make sure, I went and added Debug.Logs in the rest of my Custom actions and all of them return the log twice for each action. Apparently, the contents of the action seem to be irrelevant. Somehow AC always triggers the run() function twice...

Also, I'm using AC 1.52a and I haven't changed anything in AC's scripts... So, anyone has any idea why this may be happening?

Anyways, as usual, any advice would be greatly appreciated.

Comments

  • So a "vanilla" AC Action in the same list doesn't get run twice?  It can only be down to the code inside it - paste a sample Action so we can see what's going on.

    It could be down to skipping.  When an ActionList is skipped midway-through running, it basically re-runs all Actions instantaneously at once - though you can prevent this from happening by creating a separate overriding "Skip" function.
  • edited July 2016
    Skipping? why would it skip?... I've just left the template mostly as it was according to the first tutorial (as I don't need parameters or constant IDs). Also, I don't have a clue if the native actions are running normally, I haven't tried to touch them at all...

    Honestly, I wouldn't even have noticed the issue if it wasn't for the fact that some of my actions do some basic math making the repeating obvious. Before, most of the actions appeared to be working as intended, like the one to display alerts, but it only seemed that way because the same action was just happening (or repeating) twice too fast to be noticeable. But all I can say is that half of my actions are very simple, some of them only do stuff like changing the state of an AC global variable from true to false or viceversa. 

    Anyways, here is one of the actions I made, maybe you can figure it out if I did something wrong in it. Although, this one is a little special, because it uses Dotween(free) in the code to replace coroutines, to allow the user to specify how long to keep the menu open. Anyway, all my other scripts aren't using it, so I doubt it has much to do with the problem.

    Also, how would I do that overriding? is it like?:

    public override Skip()
    {
    }

    Then I leave it empty?
  • Please re-post on a code-sharing site like this one, instead of one with lots of pop-up ads.

    I don't know why it would skip either - I'm just letting you know that was cause a similar effect.

    Place Debug.Log statements in both your Run and Skip functions - when you see it called twice in the Console, we'll be able to use the full messages to determine when and how.
  • edited July 2016
    umm, sorry, it's juts 4shared, I never had to share code before, so I didn't know there were sites just for that... Anyway, here is the link for the code. I'll try placing Debug.Log in the skip function later today too.
  • Thanks.  It's running twice because you've got the main part of your code outside of the isRunning check.

    See the comments in the Run() function in ActionTemplate.cs.  If that function returns a non-zero float (say X), then it'll be re-run X seconds later.  This allows Actions to check if they've been completed or not.  "defaultPauseTime" is a built-in time value.  The Action will continue to be re-run until you both return 0 and set isRunning to false.

    Your Action is set up to be re-run because you return defaultPauseTime.  When it does re-run, all of the code above that gets re-run - so place it within the "isRunning" check.

    You can also do without the invoking, because if you return a value of "AlertDuration", the next time it runs will be the time that the Menu needs to close.

    Something along these lines.
  • edited July 2016
    I see, sorry, my mistake then, when I read the template I mostly just read the comments, not the code, I didn't notice you had to put the code inside the conditional? I also didn't notice it was setup to use DefaultPauseTime by default? I must admit that part had me a bit confused, but I think I'm starting to get it. So, basically, in all actions where I need them to be instantaneous, I can simply go ahead and skip the conditional and return 0f? also, thanks for that example, I'll give it a go right now, it will simplify the code, and knowing that will allow me to do other stuff too! 

    Anyways, thanks! Like I've said before, I'm an amateur, self-taught  programmer, so any help is greatly appreciated!
  • Yes, that's correct - instantaneous Actions don't need to do anything except return zero.  I left the more complex condition in the template as it's easier to remove than add.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.