how to change var in randi when _on_press?

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

what i want is to change var female_hair_style to var male_hair_style or change var “male” to “female”_hair_style in
str(randi() % female_hair_style + 1)

var female_hair_style = 6
var male_hair_style =3
var gender = “female”

	$player/hair.set_texture(load("res://player/"+gender+"/hair/hair"+str(randi() % female_hair_style + 1)+".png"))

func _on_female_pressed():
	if gender == "male":
		gender = "female"
:bust_in_silhouette: Reply From: p7f

Hi,
Well, asuming that you also have a _on_male_pressed function where you change gender to male i would do the same logic that to change gende:

var female_hair_style = 6
var male_hair_style =3
var gender = "female"
var hair_style = female_hair_style

$player/hair.set_texture(load("res://player/"+gender+"/hair/hair"+str(randi() % hair_style + 1)+".png"))

func _on_female_pressed():
    gender = "female"
    hair_style = female_hair_style

func _on_male_pressed:
    gender = "male"
    hair_style = male_hair_style

Notice i used hair_style with randi

omg! thank you very much, today i spent all my time to figure it out how to do it right, but never success. you really are my hero, thank you.

potatobanana | 2019-01-09 12:52

You are welcome!

p7f | 2019-01-09 12:53