I can’t figure out how to make an button change the gender in my stats.gd to acually store what the player chooses. I can of course do it manually but I can’t figure out how to get stats that acually updates and care what I choose.
This is an UI game.
Help
We cannot help you because we cannot see your project, know what your code looks like, what your scene tree looks like etc…
Please check this thread first:
I’m trying to turn all off this into that in Stats_Baby(or stats.gd) on the little row for “Gender”, if I press an boy button in my 2D or girl it will store the string boy or girl in that little row in Stats_Baby(or stats.gd) but I’m really new so I don’t know how. I’ve already searched but I can’t find the same problem posted.
Simply put I just want the buttons to add 1 anger if you click anger, 1 if you click Charisma and the only other thing is this input of text to be automatic.
Your Stats_Baby.new() makes a new resource that doesn’t exist in your filesystem, it is a whole different resource from this Baby_Stats.tres in your inspector. You probably get an error trying to save it as it doesn’t have a resource_path to save to.
Are you trying to run code in the editor? Changing project files in-editor is a slightly different process.
Ah yeah no I was just trying to see if the problem was that nothing happend at all that’s why I put in the print part.
So I if I wrote them into one then hopefully the text “boy” should be stored in gender on stats.gd if I click that button?
When I press the button from the editor I want it to store a string from if boy then “boy” as a text/ string should appear under gender in stats.gd
enum is not only for manual input, the only limitation is that you cannot add new values to enum once the game is running. If you only use buttons for gender selection then an enum will work perfectly fine. If you let a user type in anything to a LineEdit then you will have to use a String.
Identifiers cannot start with a number, so you cannot define enum as only numbers, but they can contain numbers later. You can also use integers or floats (which you do elsewhere) if you want numbers
I was kind of just looking for on button _pressed “Anger” for example would get +1 and it’d be stored in the stats.gd. No idea if that’s way more complicated?
Oh No I meant for the rest of my variables in the script so for “Anger”, “Intelligence” etc that will also show up as an window in the resourse. They will need numbers instead and I want a certain choice to give certain “stat”, like Anger
extends CanvasLayer
class_name Stats_Baby
@export var Name: String
enum Genders {
Undefined,
Boy,
Girl,
}
@export var Gender: Genders
@export var Anger: float
@export var Intelligence: float
@export var Happiness: float
@export var Dexterity: float
@export var Charisma: float
etc...
May I ask, when it changes the number or string is it after you load an other level that the change is applied to the stats.gd?
Because I’ve noticed that if I go in by launching individual scene press a button, exit and then reopen the resource it’s unchanged?
In-game changes do not change your game project values, the in-game changes are destroyed. It is very strange to want to save them, so I’d recommend looking through tool scripts as I’ve posted before