How to use array to change variable

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Lazyworker

I tried search some doc about that, but I can’t saw anyone
I want to random popup skill when levelup for roguelike game

my code is :

#gobal var
str = 1
agi = 2
var sk1 =  [str,1]
var sk2 =  [agi,2]

#on scren
var array = [sk1,sk2]
array.shuffle() 
rngsk =  array.pop_front() #pop sk1
rngsk[0] = rngsk[0] +rngsk[1]
# str = str + 1

print(str)    # = 2

How to do it.
Thank you

What’s the actual problem you’re trying to tackle with all of the array gymnastics? With a better explanation of the problem (not the potential solution you outline above), there’s likely a better solution.

jgodfrey | 2022-04-21 21:40

I’m updated my problem, it’s OK ?
thank for recommend.

Lazyworker | 2022-04-22 02:07

Your update is better, but it’d be nice to have a better description of what exactly you’re trying to create - NOT the code you think will do it. For example, you mention a random popup skill for a roguelike game. That’s a good start. Provide some more detail there. How do you want it to work? What should it do exactly? What are you trying to randomize?

Again, I don’t think you’re on the right path with your example code, so just ignore that for now. Try to describe what you’re trying to make, in as much detail as possible…

jgodfrey | 2022-04-22 15:52

:bust_in_silhouette: Reply From: Nighteyes

Given that I use c# and it isn’t possible there I don’t think you can. Because a point is a integer. It it was an object with a reference it would work.
However, if you print
op[0]
It should show a a value of 3.

Might I suggest you first do some basic programming tutorials to get the basics?

:bust_in_silhouette: Reply From: Fenisto

str is a build in function to convert a value to a string. So can’t use it as a variable name. But you can use it as a string.
I guess you want a list of skills with values. And then to get a random set from the combined list?

var sk1 =  ["str",1]
var sk2 =  ["agi",2]
var array = [sk1,sk2]  #returns [[str, 1], [agi, 2]]
array.shuffle() 
var rngsk =  array.pop_back()  #pop_back is faster than pop_front
print(rngsk)    # returns [agi, 2]
print(rngsk[0]) #returns agi
print(rngsk[1]) #returns 2