Random Player Upgrades with Weights to determine the probability

I created a system that triggers an event when the player reaches max XP and levels up, that event displays 3 upgrades to choose from, and those upgrades come from an array pool (MaxHP, Damage, Movementspeed ect.) and without showing any duplicates. Everything worked fine.

Now, I want to go more in depth and separate these upgrades into weighted tiers (common, uncommon, rare ect.) instead I named them with mafia themed terms (Associate, soldier, caporegime, consigliere ect.) and these weights determine the probabilty of each tier to show up along with a color-coded panel(Sprite Object) behind the text objects, I know that I need to separate the text objects into 3 parts, 1st would be the name of the tier, 2nd would be the type of upgrade, and 3rd would be the value of that upgrade, and on top of that the weight calculation result is also affected by the player’s luck level as well. I created a main structure->list of upgrades as structures-> in each upgrade is an array of the tiers and their own set of variables.

Mind you that I used AI to put all this code together but reached a point where I lost track and could not figure it out. Also please keep in mind that as a designer, when it comes to complex math I just can’t wrap my head around it. And finally I ended up with this mess that freezes the game upon leveling up.


would really appreciate anyone’s help here. <3

1 Like

Hey!

I made an extension for weighted randomization which you can learn about here:

AdvancedRandom Extension

Hopefully this helps! :smile:

2 Likes

My friend, is there a possibility to get in touch somehow, because I simply don’t know what to do here, let me know if you. Much appreciated!

1 Like

Of course!

If you click on my profile, you can hit “Message” and send me a private message and we can chat there, or we can chat here in replies!

Is it a problem you are having with the extension, or just not sure how to use it?

1 Like

The extension is probably everything I need, I just dont know how to use it.
I have been completely relying on Ai, but when it comes to getting deeper into the code, I stopped getting results, Ai tells me to do somthing then tells me that it is wrong, stuck in a loop, good thinkg I backed up my project because now it is a mess, I couldnt find the message icon you mentioned so it will have to be here I guess, let me know if there is an alternative way of getting in touch.
Anyway here is what I ended up with, but now when I reach maxXP the game pauses but no upgrade panels are showing

the log says theat the repeat 3 times is executing, but results are 0 everytime therefore nothing is showing, and I barely understand what that even means XD

Also I changed the global variables to look like this for better efficiency in the code (let me know if that was a good idea or not) as an attempt to retry the whole thing with Ai

But again was just running in circles, and got stuck again

1 Like

I see a problem.

If you are using Accuracy_Tier’s for your weighted randomization, that won’t work. Let me explain how the weighted randomization works:

You have one structure variable. In this case, let’s name it “Tiers”.
In the structure variable, each child has a name and a number variable. For example, “Accuracy1” with a value of “50”.
Lets say you add another child, “Accuracy2” with a value of “25”.

Now, you would add an action “Change variable value” with a variable name such as “Tier” and change it’s value to the AdvancedRandom::WeightedRandomization(Tiers).

How the weighted randomization works is it adds up all the values (50 + 25 = 75) then picks a random number (such as 60) and then figures out which child it has chosen. This means that the higher the weight is, the more likely it’s chosen.

Summary:
You need one structure, where each child variable has a name and a number value for its weight. You then need to use the “AdvancedRandom::WeightedRandomization()” function inside of another action, such as “Change variable value”.

(Hopefully this was easy enough to understand! :smile: )

1 Like


So is this structure concept better?

1 Like

Yes…but there are still a few changes that need to be made.

The structure named “Tiers” must ONLY contain the weights, with the values of the weight. You cannot have any info such as Rarity or Stat_Bonus in that structure, otherwise the weighted randomization won’t work. It needs to look like this:


(Got to go at the moment, but can explain more later if needed.)

1 Like


Ok so now I have this structure, is that what you meant?

1 Like

Yep!

Unfortunately, I’m not 100% sure if decimals work in the weights. The best way to do it would probably be to multiply each weight by 10 (so that your decimals turn into full numbers).

Then, when you need to choose the weighted randomization, you’d use this event:


(“ChosenUpgrade” can be whatever variable you want to store the result in. The result will be a text and will be the name of the chosen tier, such as “CashXPGain5”).

2 Likes

I really do appreciate that you are trying to help, but I just am unable to manage, this upgrade system I am trying to create is too complicated for me, I keep having to revert to Ai because I can’t explain where I am in the forums all the time, and it tells me to restructure the variables, and again I keep going back and forth with no results, I would love to learn how this complex code works but I am simply getting lost, my question to you is, can I send you the project for you to tell me what I am missing? I’m sure that if I have that 1 critical calculation that I need, and I can confidently say that I will be able to continue from there. Again I thank you from the bottom of my heart for your assistance.

1 Like

I’m sorry but I’m not really the best for examining code and finding problems…

Maybe @MrMen or @Keith_1357 could take a look?

1 Like

Familiar about this, is this about “Rarity of lootbox” problem (where you have high chance of getting common and less chance of getting legendary)?

1 Like

I had done this, i use “1/n” method.

Variable (Scene)

Event

Example of usage:



i forgot to put 1 on “1 in (n) of getting common” input

1 Like

I would actually stick to your UpgradesDatabase Structure. If you simply change the thing into an Array of Structures you can loop through it conveniently with loop counter variables.

I just made a small example using your DataStructure (just as an array of structures):

Events for weighted picking:


Upgrades Data Structure (AoS):

Local Variables of the actual picking:

3 Likes

This is a lot to read. There are a lot of different attempts. Let’s restart.

Can you get the random extension to work. Before trying to use it in your project maybe you need to try it in an empty project. Just to learn the fundamentals of the process.

It seems to need a structure with say the tier names with a value of the weight. And the another structure with the items in each tier. And then choose from that structure or array.

Like

Powerups
...Tier1=50
...Tier2=20
...Tier3=10
...Tier4=5

The extension will pick a random child influenced by the weight.

You’ll now have the name of the tier. You could now use the tier name to dynamical access the child or structure or array in another structure.

Start with just understanding the extension.

The other variable would be like

PowerupsList
... Tier1
... ... Array or structure of items
...Tier2
... ... Array or structure of items
...Tier3
... ... Array or structure of items
...Tier4
... ... Array or structure of items

The 2nd array has nothing to do with the weighting. You access that variable with the string from the extension.

Say you saved the child name from the extension as RandomTier. You’d access the structure or array with…

PowerupsList[RandomTier]

You could then get your item(s) from that structure or array.

It would probably be easiest to feel comfortable with this concept in a solo project where you can focus solely on this concept.

3 Likes