system
August 6, 2021, 2:22am
1
Attention
Topic was automatically imported from the old Question2Answer platform.
Asked By
Dumuz
For example:
var power_up = 5
func _ready():
print(#some method(power_up))
#prints power_up
Since you want it to print the word “power_up”, isn’t the (daft) solution to just print("power_up")
. Since you would need to specify the name of the variable to tell it which variable name to print out, you’re basically just printing the name of the variable!
SteveSmith | 2023-01-05 14:53
system
August 6, 2021, 5:20am
2
Reply From:
fractavius
Not sure what your method does, but you should be able to do this:
func _ready():
method(power_up)
print(str(power_up))
So if I have var power_up = 6
I want to be able to print out the name itself.
print(str(power_up))
#prints the number 6.
I want print()
to print “power_up”, but because of printing the variable name itself, is there a method for this?
system
August 6, 2021, 5:41am
3
Reply From:
Help me please
You can convert any integer into string by using str()
in your case:-
var power_up = 5
func _ready():
print(str(power_up))
#this prints power_up
If you want to convert this string into integer again then you can use int()
var power_up = "5"
func _ready():
integral_power_up = int(power_up)
So if I have var power_up = 6
I want to be able to print out the name itself.
print(str(power_up))
#prints the number 6.
I want print()
to print “power_up”, but because of printing the variable name itself, is there a method for this?
I don’t think if there is a method to print the name of variable . If you have do so then you need to do this manually
var power_up = 5
func _ready():
print(str(power_up))
#this prints value of power_up
print("power_up : " + str(power_up))
#this prints "power_up : 5"
Help me please | 2021-08-09 06:12