How to setup this function with the correct condition for this branch?

Hello everyone,

I am having a bit of a problem with this function. What this is supposed to do is:

First Click Button A: Exec comes in the function, checks if Array Key= with Saved Array Key then gets and, sets the Array Key but Boolean is false.

Second Click Button A: Since Get Array= Saved Array Key then Boolean is set to True.

Now when I click on any other button it should get the other buttons Names and set them.
So the first click at any button should be false and the second true.

Now what actually happens is Click Button A then Click Button B and then Click Button A again still gets the function to set the Boolean to True.

Now I have noticed that this happens like this: If I click at any given button once then the second time will always set the boolean to true even if there is some other button clicked in between.

So I am thinking that I might have misunderstood the Set Name node… Perhaps it is Adding the Array Key to the Name Variable instead of setting just setting the current?

Anyway, I hope I was clear on the issue,
thank you all in advance!

Local variables in functions come into existence when the function starts running. So no matter how many times you run the function, it’s always like the first time you ran the function.

If you want the variables to be consistent between runs, you have two options:

  1. Don’t use local variables, use variables in the main blueprint body.

  2. Don’t use functions, use macros.

Thanks for the response! I think the problem that persists is the naming I mentioned… I expanded the function and used a normal variable but still no luck.

I remade it to the simplest form I could think of so I can avoid any mistakes…

Button 1 makes the array stop at 1 so Array Index for Bool is set to 1
Button 2 makes the array stop at 2 so Array Index for Bool is set to 2
Button 1 should again set the Array Index to 1 but instead, it goes to true

I’m afraid I can’t debug it unless I can see all the code.

For instance, what’s putting keys in the array?

Sorry, here is the code from start to finish.

It shows how I am making the map and then letting the array determine which button was pressed. Then I am using the array index to get all the stored info on the screen plus to determine if it is the first or the second time this particular button is being pressed.

I think I have a clue as to why this is happening. When printing the array index into a string this is what comes back in the log before I click anything.

LogBlueprintUserMessages: [Fire_Talent_1] 0=0
LogBlueprintUserMessages: [Fire_Talent_2A] 0=0
LogBlueprintUserMessages: [Fire_Talent_2B] 0=0
LogBlueprintUserMessages: [Fire_Talent_2C] 0=0
LogBlueprintUserMessages: [Fire_Talent_3A] 0=0
LogBlueprintUserMessages: [Fire_Talent_3B] 0=0
LogBlueprintUserMessages: [Fire_Talent_3C] 0=0
LogBlueprintUserMessages: [Fire_Talent_4A] 0=0
LogBlueprintUserMessages: [Fire_Talent_4B] 0=0
LogBlueprintUserMessages: [Fire_Talent_4C] 0=0
LogBlueprintUserMessages: [Fire_Talent_5] 0=0

After I click Button 1:

LogBlueprintUserMessages: [Fire_Talent_1] 1=1
LogBlueprintUserMessages: [Fire_Talent_2A] 0=0
LogBlueprintUserMessages: [Fire_Talent_2B] 0=0
LogBlueprintUserMessages: [Fire_Talent_2C] 0=0
LogBlueprintUserMessages: [Fire_Talent_3A] 0=0
LogBlueprintUserMessages: [Fire_Talent_3B] 0=0
LogBlueprintUserMessages: [Fire_Talent_3C] 0=0
LogBlueprintUserMessages: [Fire_Talent_4A] 0=0
LogBlueprintUserMessages: [Fire_Talent_4B] 0=0
LogBlueprintUserMessages: [Fire_Talent_4C] 0=0
LogBlueprintUserMessages: [Fire_Talent_5] 0=0

And after Button 2:
LogBlueprintUserMessages: [Fire_Talent_1] 1=1
LogBlueprintUserMessages: [Fire_Talent_2A] 2=2
LogBlueprintUserMessages: [Fire_Talent_2B] 0=0
LogBlueprintUserMessages: [Fire_Talent_2C] 0=0
LogBlueprintUserMessages: [Fire_Talent_3A] 0=0
LogBlueprintUserMessages: [Fire_Talent_3B] 0=0
LogBlueprintUserMessages: [Fire_Talent_3C] 0=0
LogBlueprintUserMessages: [Fire_Talent_4A] 0=0
LogBlueprintUserMessages: [Fire_Talent_4B] 0=0
LogBlueprintUserMessages: [Fire_Talent_4C] 0=0
LogBlueprintUserMessages: [Fire_Talent_5] 0=0

So naturally, when I click back to 1 it is going to check if 1 is equal to the preexisting 1 that was set before. This button is a widget that is put multiple times in another widget… I am thinking that I should have stored the variable in the widget that is housing the buttons so it won’t be assigned to all of them but I am so confused at this point.




Ok, that looks like a bit of a nightmare. Maybe if you can describe what you’re trying to do in abstract terms ( forget about the code ).

I see you have widgets, powers, and the player can press a key? Or more than one key, or?

Wow, and I thought I was keeping my stuff tidy :sweat_smile:

Ok, so I have a Widget that serves as the housing for the buttons. This is Talents Widget. Basically, it is something like the talent tree from Wow or similar games.

I have another Widget called Talents Button Widget. Inside Talents Widget I have 11 x of the Button Widget. I have already succeeded in buying talents with points and displaying the correct description etc.

What I am trying to do now is: Tap Skill 1 once displays its description but tapping on it a second time WITHOUT tapping anywhere else should enable that skill for the player. (The player can buy all of the talents but there are two of them which are active abilities and the player must choose between them).

Here is what I tried to do with the code:

I assigned IDs to each of the Buttons by making an ID Name Variable in Talents Button Widget and then making it Instance Editable and Exposed on Spawn. This way in the Talents widget I gave Individual IDs.

So now I am using this ID in the Talents Button Widget, where I am writing the code, to determine which button is pressed. I do that by comparing an Array of the Buttons ID to the ID of the button being pressed.

So if Button 6 is pressed the array will store that Array Index in a variable which I later use to print the proper talent descriptions for the player to read.

1 Like

Ok, I found my error.

The problem was that I was trying to save the array’s index output as an index variable in the Talents Button Widget…

So it was storing it for that individual button while my intention was to just have a single number for all of the buttons which will be changing every time for the Branch to work.

I simply moved the saving of the variable from the Button Widget to the Talents WIdget that is housing the buttons and it worked.

Thank you for taking the time ! I’ve been stuck 3 days on this :sweat_smile:

1 Like

Excellent. So, in fact using what was basically a local variable ( local only to the widget ), was the problem :slight_smile:

1 Like