Need help with array!

I am pretty new to the engine and yet unexperienced with using an array. What I want to achieve is …


In this one add the ‘button 124’ to the disabled buttons array inside Savegame. (Did I even do it right?)

and here I want to call the disabled buttons and destroy it. In this one, I have little to no idea what to do. Any help would be appreciated. Thanks!

Hey YUHBE3!

In the first screenshot you can just use a “Get” instead of a “Set” from “SGO_LevelLock” for the disabled buttons array, then plug that into the “Add” with “Button 124” as the object. I don’t think you need that green function down below. I believe it’s “create array”? But you won’t need it because you have an array: “Disabled Buttons”.

As for getting rid of that array, if you want to just get rid of everything inside you would use the “Clear” node instead of the “For Each Loop” and plug the array into that. Give that a shot and let us know how it went!

1 Like


I want to add button 124 to disabled buttons array when once it is pressed,

and destroy it on event construct, but it doesn’t seem to work. Any idea? :frowning:

Okay, I see what you mean now. Sorry for the misunderstanding!

Instead of “Clear” you’ll want to use a “ForEachLoop” and from “For Each” use “SetEnabled” with a false boolean. Like so!

1 Like

I get a error that set is enabled is accessed to none. Any idea?

That means the reference you’re trying to access is not valid (null). A safe way to avoid trying to access null references is by using a “IsValid”.

Let’s throw an IsValid check in there before the Set Is Enabled!

Update: good call @Squize. I was just not fast enough!

2 Likes

OH MY GOD it worked. I’ve been stuck on this for whole day. Thank you sooooo much. Have an awesome day!!

2 Likes

I thought it worked because the button was disabled from the start for the first time. I thought it was disabled because I clicked it before but when I tested the whole game apparently it is permanently disabled. Why is this? :frowning:


event construct

on button pressed

I’ll add link to the proposed solution here aswell Can someone PLZ tell me what's wrong with my code? - #3 by Squize