what is the value of the variable int that I want to add to the script?
I have made an array actor reference and added all the static mesh actors in the scene… the name “barrel 00” actually was I mistake but I went on with it… didn’t think it is going to be a problem… could it? is it possible that it cant read any value because of “00”?
also how can I check if the index in my array is actually valid?
In the screenshot I provided is already an implementation of how to check whether your index is valid or not. I also mentioned in the original reply (the one where the screenshot didn’t get attached for some reason) that the initial value of your int should be 0; since you will be starting at the first index of your array, which is always 0.
Variable names only matter when referencing them; their name doesn’t have anything to do with their value. You could have called your barrel00 “clownscar” and it would have still worked, as long as your variables actually have a reference in them.
Could you show me exactly where you set the variables barrel00 and so on?
so, I have created a bar and my main quest is to collect a stack of barrels from the bartender to the back room. I have created a BP class and added all of the static mesh components to the BP class. I have a problem though… I cant seem to collect everything.
I made the script using array and my idea is to make each barrel disappear at a time and I did it with the “toggle visibility” node. but I always manage to either get everything to disappear or just nothing happens.
I tried to add either the " for loop" node or " switch on int " node but I always have the same problem.
can someone help me or advise me how can I make this work??
Even if I understand your problem, you should totally add some screenshots of your code, it’s easier to follow and there is a chance we see something that you didn’t <3
Personally, I still don’t know when you want to make them disappear. The code you are showing is telling me, everytime the player presses a button, you want to toggle the visibility. I don’t know which one you want to make disappear and when and how everything should work with the players input :3
First of all; when you request the length of an array, it will always return the number of items in the array, not the index they are at. Since arrays start at 0, it means that an array with a length of 1 only has an item in index 0. Trying to call said item using “length” without subtracting 1 from it should lead to out of bounds errors (and, obviously, nothing actually happening as there should exist nothing at array[length of array]).
Anyway, that’s the explanation, but from hat I read what you want to do; drop the for loop; you don’t need it. Instead, go with a setup like the one below (warning; untested).
What happens is that first you check whether the index in your array is actually valid so you don’t get any out of bounds problems. Second, you get the item at the Index variable (starting at the default value of 0, so you start with the very first item in the array). Then you toggle visibility of the item you got from the array and then you increase the Index variable by 1, so that next time you press the button the function will continue to the next item in the array (of course, only when the index is valid).
In the setup you posted above, you need to have an int variable that you add 1 to after every time you toggle the visibility of one of the barrels. I recommend my way however, as yours is horribly time consuming if you are going to have multiple levels, since it only works with a fixed amount of barrels and would require you to make another one every time.
Also, are you properly initializing those barrels? As in, do the variables saying “barrel 00” and so on actually contain a reference to the barrels in the level?