Object variables seem to always break when there are multiples of said object

Okay so hear me out for a second. I know there are like seven billion other users with a similar issue, but I couldn’t find someone with my specific problem, and it’s been frustrating me ever since I started working on this specific project like a month ago.
I have an enemy object that I am programing AI for, his name is Bunnydude. He has floppy bunny ears, and he can do this long swooping arm attack that I learned sin() and cos() to create!

Screenshot 2023-09-28 170332
Screenshot 2023-09-28 170428
Screenshot 2023-09-28 170449
Screenshot 2023-09-28 170515

The player can also play as Bunnydude, and he’s really fun to control! I didn’t wanna duplicate objects in the editor, because that gets really messy. So, I only used one object, and I keep track of which is which with an ID variable. Players use negative IDs, starting at -1, and NPCs use positive IDs, starting at 1.

At the beginning of the scene, it gives all the pre-existing objects a unique ID that starts at 1 and counts up. I will refer to NPC objects as 1.
Then, it spawns the player, and gives them an ID of -1. I will refer to player objects as -1.

For -1, it just grabs keyboard inputs, and stores them in the input array for that object.
For 1, it has AI events that trigger when certain things happen, that triggers the variables in the input array of object1.

Now for the ISSUE.
Things just break. At the begining of the scene, the bunny ears and the arm swing attack break, all the ears seeming to only go to one of the bunnies with all the other bunnies being earless.

And the attack does… this. It never swings, and never disappears. Holding down the button creates new arms constantly, creating this paint smear effect:

Not to mention, all the movement breaks after a while. It only happens while the player is pushing buttons I think. When movement breaks, it’s like the input array just doesn’t exist anymore, cause nothing inputs or does anything, no matter what you try. If you’re mid jump, you will finish the whole jump and reach the floor fine, so they game isn’t crashing…

Note, I programed my own physics that use object points and positions, and variables. I didn’t use the default physics engine, cause it is so incredibly janky. I will give examples of the default physics engine not working if they are needed, and I will also provide my custom physics events if needed, although, they’re very rudimentary, and they aren’t what’s causing issues, I know that’s for sure. I think it has something to do with how “Repeat for each object:” events work, but I’m not sure exactly how.

Screenshot 2023-09-28 171059

Any help is greatly appreciated, even if we don’t fix the issue. Redirect me to a different topic if my exact issue really WAS already posted here, but I’m 99% sure it wasn’t!

We’re going to need a little more than that. Just a screenshot of the relevant events. Let’s deal with one issue at a time. Instances can be tricky and variables can seem fragile but there’s usually a method to the madness.

1 Like

Alright. Let me just add some extra comments too so they’re a bit more readable.

1 Like

Input handling

The start of Bunnydude’s events (I skipped stuff I was 100% sure is irrelevant)

Code for Bunnydude’s arm

Code for bunnydude’s ears.

Also, thats literally almost all of his code. I probably could have just sent a few things, but to be honest, I’m not exactly sure what is and isn’t important. It’s probably a super small issue too.

Your last image. You’re using for every bunny ear I think that should be for every bunny dude

(this is not something I thought I would ever say)

1 Like

Oh hey wow, that fixed the ears!
I can fix the Z Order issue as well, very easily.

But I’m still having that input issue, where after a while you just can’t control him anymore. It’s not for a similar reason either.

Oh oh wait! I discovered something,
It’s just jumping and the ears not turning with the bunny guy. If I spawn him in the air, I can still strafe, and I can attack at any time just fine.

The control issue is a little more complex. I’m not the person to fix that one.

1 Like

Alright, well, thank you for the help! <3

1 Like

Well, I think I fixed it. Something about using trigger once on the jump event caused 2 bunnydudes jumping at the same time to make the jump button get stuck.
I understand how that happened, but it’s kind of dumb. I thought that repeating it for multiple objects meant, each object ran the code separate, isolated, and that a trigger once wouldn’t apply to all of them like that, if that makes sense?
Like, trigger once wouldn’t just, trigger once on one instance, and then proceed to not check AGAIN for other instances. Like what the heck, am I dumb or is that just odd?
In any case, I learned a new thing about “Repeat for each object”, and trigger once is weird :b

1 Like

Yeah, **trigger once ** inside loops doesn’t usually work as expected. They’re usually not needed. If needed a boolean variable works better.

1 Like