The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

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

in Engine by (26 points)
edited by

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.

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

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...

2 Answers

0 votes

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?

by (57 points)
0 votes

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
by (88 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.