Local Variables

Started by Ch336ico on

Topic category: Help with modding (Java Edition)

Last seen on 22:24, 31. Jul 2024
Joined Jul 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Local Variables

The local variables resets once the procedure run again? For example, I have a local variable of an entity that get the entity that I hit in the procedure "When living entity is hit with tool", everytime I do a new hit in the same entity the variable resets?

Last seen on 15:36, 5. Aug 2024
Joined May 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Correct, the variable is…
Mon, 07/08/2024 - 14:47

Correct, the variable is reset after every trigger.The variable only exists in that instance of the procedure.  it also causes it so that the procedure can run multiple times at once and still be separate variables. When the procedure finishes, the variable is now nonexistant until the procedure is recalled since it only exists inside that one procedure .

To not do this. make a global variable.

-PixelKid

Last seen on 22:24, 31. Jul 2024
Joined Jul 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thanks again! You are…
Mon, 07/08/2024 - 15:11

Thanks again! You are salving my life ngl, but how do I do a global variable of an entity if there is no entity type variables in the global section?

Last seen on 15:36, 5. Aug 2024
Joined May 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Currently there is no direct…
Mon, 07/08/2024 - 21:18

Currently there is no direct support for that, but the best workaround is to create a string variable and store entity data plus variable in it. Like: entityiszombie_variable, but i don't know how well this will work.

I haven't done this so I can't help to much in this.

-PixelKid

Last seen on 22:24, 31. Jul 2024
Joined Jul 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Alr I will try, thx
Mon, 07/08/2024 - 22:41

Alr I will try, thx

Last seen on 15:36, 5. Aug 2024
Joined May 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Sorry for not thinking of…
Thu, 07/11/2024 - 13:13

Sorry for not thinking of this sooner, But I just realized that you can assign NBT tags to an entity. I haven't really done this before. The way to do it is put the variable inside the NBT tag and add it to the entity.

To see if it has the TAG, do :

if entity had _ NBT tag

then: _

to change:

remove _NBT tag of entity

add _ NBT tag to entity

Hope I helped! PixelKid