[SOLVED] Procedure Triggers Fired Every Tick Break Local Variables

Published by rmsandegs on
Issue description

I don't know whether this is technically a bug or not, but I am listing it as one because I feel that this is not intended behavior.

The problem is that the local variables are registered every time the procedure is triggered, so they reset to 0 every time the procedure is called. Example:

Pircure of procedure (right click > open image in new tab if you can't see)

The variable "effectTimer" is registered and set to 0 every time "executeProcedure" is called, so it will always be 0 and thus the condition will never be met, no matter how many times the procedure is fired.

My way of remedying this is to register effectTimer outside of executeProcedure, so it is set to 0 once when the procedure is initialized and never again. Now the condition can be met:

Picture of "fixed" procedure (open image in new tab if you can't see)

One potentially dangerous side effect of doing it this way is that executeProcedure can now no longer be static or it can't reference / modify effectTimer-- At least, it can't according to my testing and my limited knowledge of Java. I hope this issue can be solved without a re-write of the entire way procedures are called.

EDIT: Upon messing with this some more, the situation looks pretty intense. I had to make the entire EffectCustom class that triggers the procedure non-static, and create a variable instance of the procedure just to get this to work, which it does, but still not ideal. I'm probably missing a very simple solution somewhere but this is the conclusion I came to with my limited understanding.

Issue comments

and create a variable instance of the procedure

No don't do this, this will not work with multiple variation of same element.

 

Local variable is local by its definition and is not meant for this.

Please look at https://mcreator.net/wiki/variables

To make block timer for example, store counter in NBT, not in local variable which is not intended for this. In general you need to bind counter to some type of data storage, be it NBT or global variable.

I see. Well in that case, I'll just bind it to the entity's NBT, as I will need a separate counter for every entity that has the effect. Thanks for the link as well. It was very informative.