0 votes

why my traits_dis did't change when i get traits_ID == previous_trait_id, but traits_ID change.

when i print my traitsID, it change, but my traitsdis$characterstat/VBoxContainer/traitsnote.settext(traitsname + " : "+traits_dis) did't change.

example:
traits_ID:
1
2
3

traits_dis:
6 int, 3dex
5con, 1int
1 wis

~~~~~~~~~~~~~~
when first click i get
traits_ID 1 then my traits_dis should be 6 int,3dex
when next click i get same traits_ID, and my loop working.
traits_ID 3 then my traits_dis should be 1wis

but i get
traits_ID 3 then my traits_dis is 6 int,3dex

my traitsID change but not my traitsdis

what should i do?

what i want to is , i dont want to get same traits in row, for example if i click three time , i dont want it to be traits 1,traits 1,traits 3 or traits 3,traits 1,traits 1. i dont mind if become like traits 3,traits 1,traits 3 or traits 3,traits 1,traits 3.

var previous_trait_id = -1
func traits():
    randomize()
    var traits_ID = randi() % (ImportData.traits_data.size()) + 1
    var traits_dis = ImportData.traits_data[str(traits_ID)].traits_discription
    var traits_name = ImportData.traits_data[str(traits_ID)].traits_name
    var traits_Value = ImportData.traits_data[str(traits_ID)]


    while traits_ID == previous_trait_id:
        traits_ID = randi() % (ImportData.traits_data.size()) + 1
    previous_trait_id = traits_ID

    $character_stat/VBoxContainer/traits_note.set_text(traits_name + " : "+traits_dis) 

    print("traits_dis ",traits_dis)
    print("traits_ID ", traits_ID)


func _on_traits_pressed() -> void:
    traits()
in Engine by (380 points)
edited by

1 Answer

+1 vote
Best answer

Well you need to modify like :

    var previous_trait_id = -1
func traits():
    randomize()
    var traits_ID = randi() % (ImportData.traits_data.size()) + 1
    var traits_dis = ImportData.traits_data[str(traits_ID)].traits_discription
    var traits_name = ImportData.traits_data[str(traits_ID)].traits_name
    var traits_Value = ImportData.traits_data[str(traits_ID)]


    while traits_ID == previous_trait_id:
        traits_ID = randi() % (ImportData.traits_data.size()) + 1
        traits_dis = ImportData.traits_data[str(traits_ID)].traits_discription
        traits_name = ImportData.traits_data[str(traits_ID)].traits_name
        traits_Value = ImportData.traits_data[str(traits_ID)]

    previous_trait_id = traits_ID

    $character_stat/VBoxContainer/traits_note.set_text(traits_name + " : "+traits_dis) 

    print("traits_dis ",traits_dis)
    print("traits_ID ", traits_ID)


func _on_traits_pressed() -> void:
    traits()
by (52 points)
selected by

i thought i just need to update ID only. thanks

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 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 webmaster@godotengine.org with your username.