I haven’t added any other values (traits) yet. Just those four for now.
so, just to be clear: the order of the traits doesn’t matter?
like it won’t matter if e.g. romantic is trait1 or trait3?
Correct. I just need the traits to not repeat themselves. Like if trait1 is the same as trait2 or 3.
*rand traits 1 5
*if (traits =1)
*set trait1 "romantic"
*set matchromantic true
*set trait2 "fertile"
*set matchfertile true
*set trait3 "compassionate"
*set matchcompassionate true
*goto next
*elseif (trait =2)
*set trait1 "romantic"
*set matchromantic true
*set trait2 "fertile"
*set matchfertile true
*set trait3 "loyal"
*set matchloyal true
*goto next
*elseif (trait =3)
*set trait1 "romantic"
*set matchromantic true
*set trait2 "compassionate"
*set matchcompassionate true
*set trait3 "loyal"
*set matchloyal true
*goto next
*elseif (trait =4)
*set trait1 "romantic"
*set matchromantic true
*set trait2 "compassionate"
*set matchcompassionate true
*set trait3 "fertile"
*set matchfertile true
*goto next
*else
*set trait1 "fertile"
*set matchfertile true
*set trait2 "compassionate"
*set matchcompassionate true
*set trait3 "loyal"
*set matchloyal true
*goto next
i thiiiiink that should cover all possible combinations. if i forgot one, just add that and got for the rand for 1 6
Thank you for taking the time to even try to deal with this jumbled code!
Your code was a little buggy, but I fixed it for now. I changed all your “trait” 1-3 to “matchtrait” 1-3 because that’s what they were known as prior to.
Other than that, it seems to run fine and it hasn’t given me two of the same traits or a number. I’ll try adding in more traits to see if any repeat themselves. Thank you! You might have both simplified and fixed my problem.
Happy i could help
Since there are more than three traits to choose from…um…just trying to figure out how to change your code around to accommodate that. You said go for the *rand, right?
Like…for example, under your first trait = 1 with compassionate as the final trait set…with *goto next as the following command, how would I implement more trait options within that first setup? Does that make sense? It seems like there’s only code for three traits to be set, with three values to choose from. I’d like to add more values to choose from.
It depends on how many traits you wanna have.
Right now its 4 (loyal, fertile etc) on three “slots”
The code assigns the possible combinations to the slots
I might be totally misunderstanding your code (I do that a lot), but if it is what I think it is, this method would be really time consuming and text-heavy when you start to add in more traits. As I understand it, each possible value for “trait” has a combination of three static traits which will be assigned?
From a set of only four traits, the code works because there are only four possible combinations. But if you up the number of traits to be chosen from, the number of combinations starts increasing fast. From a set of twenty possible traits, choosing three, regardless of order, with no repetition, equals just over one thousand combinations. Which means “trait” would end up needing to randomize between 1 to 1140, which equals a whole lotta code.
Three static traits, yes. I feel like this isn’t meant to be complicated. I can’t just have four trait options to choose from. That would get severely boring.
I guess I could take out this part of the randomization. Allow the player to choose specifically this section. But that just sucks, you know, because it’s meant to be random.
Looking back over your code, I see what you did to make it work. I would have to add more traits as variations…sucks I can’t just make it all more random.
Okay, I went through your code again and cut it down to this, which works for me when I run it on it’s own (excluding the creation of the variables) in randomtest-
*comment randomize matchtrait1/2/3
*rand matchtrait1 1 4
*rand matchtrait2 1 4
*rand matchtrait3 1 4
*comment loop to ensure unique values
*label checktraits
*if (matchtrait2 = matchtrait1) or (matchtrait2 = matchtrait3)
*rand matchtrait2 1 4
*goto checktraits
*if (matchtrait3 = matchtrait1) or (matchtrait3 = matchtrait2)
*rand matchtrait3 1 4
*goto checktraits
*else
*goto matchcontinue
*comment set final traits
*label matchcontinue
*if (matchtrait1 = 1)
*set matchromantic true
*set matchtrait1 "romantic"
*if (matchtrait1 = 2)
*set matchfertile true
*set matchtrait1 "fertile"
*if (matchtrait1 = 3)
*set matchtrait1 "compassionate"
*set matchcompassionate true
*if (matchtrait1 = 4)
*set matchtrait1 "loyal"
*set matchloyal true
*if (matchtrait2 = 1)
*set matchtrait2 "romantic"
*set matchromantic true
*if (matchtrait2 = 2)
*set matchtrait2 "fertile"
*set matchfertile true
*if (matchtrait2 = 3)
*set matchtrait2 "compassionate"
*set matchcompassionate true
*if (matchtrait2 = 4)
*set matchtrait2 "loyal"
*set matchloyal true
*if (matchtrait3 = 1)
*set matchtrait3 "romantic"
*set matchromantic true
*if (matchtrait3 = 2)
*set matchtrait3 "fertile"
*set matchfertile true
*if (matchtrait3 = 3)
*set matchtrait3 "compassionate"
*set matchcompassionate true
*if (matchtrait3 = 4)
*set matchtrait3 "loyal"
*set matchloyal true
Traits: ${matchtrait1}, ${matchtrait2}, and ${matchtrait3}
*finish
So, the label “checktraits” will repeat through itself until all three variables have different values. Then it gets sent to the label “matchcontinue”, which sets matchtrait1/2/3 to strings and the corresponding matchromantic/matchfertile/ect… to true.
I think your math is a bit off.
Its not over thousand
Thank you for testing this and writing it up again.
I’m sorry it’s so complicated. This is what I get for wanting randomized traits. If I only made everyone have one trait, that’s easier…but try three and my mind explodes. lol.
I have three choices right now and I’ll probably try them all to see which works best for me. I can try to implement your code with the rest of my 20+ traits, I can work with Meltingpenguin’s code and just add literally a million variables and combinations, or I can try to add some type of personality choice to the game.
Within that personality choice, there could be maybe three varying trait options using Meltingpenguin’s code. This could work…it will be a lot of code, but maybe I can get it to not loop.
It’s no problem! I actually really enjoy coding, and it’s nice to distract myself from my own mind-exploding coding troubles lol. Hopefully everything works out and you wont have to give up randomized traits, I think they’re a great idea!
So I didn’t check the code that much, still trying to understand how exactly it works. I might have an idea for a way to handle higher number of traits with simpler coding.
There are traits like Kind, Honest, Loyal etc and then the randomizer simply assigns these to people? And your code checks to make sure they weren’t already assign and if so re-randomizes until it’s not one of the already assigned traits?
How many traits can one person have?
The randomizer assigns traits, there are three trait slots per person. Everyone can have three traits. These traits can not repeat on the same person. Like: Compassionate, Loyal, Compassionate.
Ok, I went ahead and did a randomizer trait system. You can have as many traits as you want, as many characters as you want and as many traits for each character as you want.
This uses arrays so if you do try dwelving on the code you might need to read up on them a bit, but you can still use it without knowing about them since I tried to make the code simpler to be used.
(Most of the code is not necessary, it’s simply because I added 3 methods to show the traits of each character. You could simply pick the one you feel most comfortable with).
*title Trait randomizer
*author GS
*create implicit_control_flow true
*create repeated_traits 0
*create space " "
*create search_id 0
*create search_trait ""
*create search_result false
*create search_match_slot 0
*create trait_1 "Compassionate"
*create trait_2 "Tall"
*create trait_3 "Strong"
*create trait_4 "Pretty"
*create trait_5 "Patient"
*create trait_6 "Smart"
*create trait_7 "Diligent"
*create trait_8 "Just"
*create trait_9 "Honest"
*create trait_10 "Shy"
*create trait_11 "Young"
*create trait_12 "Greedy"
*create trait_13 "Brave"
*create trait_14 "Groomed"
*create trait_15 "Stubborn"
*create trait_16 "Fussy"
*create trait_17 "Curious"
*create trait_18 "Playful"
*create trait_19 "Quick"
*create trait_20 "Humble"
*create trait_quantity 20
*create char_quantity 10
*create allowed_traits 3
*create char_1_1 "Michelle"
*create char_1_2 ""
*create char_1_3 ""
*create char_1_4 ""
*create char_2_1 "John"
*create char_2_2 ""
*create char_2_3 ""
*create char_2_4 ""
*create char_3_1 "Kevin"
*create char_3_2 ""
*create char_3_3 ""
*create char_3_4 ""
*create char_4_1 "Erica"
*create char_4_2 ""
*create char_4_3 ""
*create char_4_4 ""
*create char_5_1 "Jackson"
*create char_5_2 ""
*create char_5_3 ""
*create char_5_4 ""
*create char_6_1 "Samuels"
*create char_6_2 ""
*create char_6_3 ""
*create char_6_4 ""
*create char_6_5 ""
*create char_7_1 "Merlin"
*create char_7_2 ""
*create char_7_3 ""
*create char_7_4 ""
*create char_8_1 "Stanley"
*create char_8_2 ""
*create char_8_3 ""
*create char_8_4 ""
*create char_9_1 "Waits"
*create char_9_2 ""
*create char_9_3 ""
*create char_9_4 ""
*create char_10_1 "Ripley"
*create char_10_2 ""
*create char_10_3 ""
*create char_10_4 ""
*choice
#Randomize traits.
*gosub randomizer
@{(repeated_traits > 0) Traits got repeated during randomization ${repeated_traits} times and were re-randomized|No trait got repeated during randomization}.
*label finishing
*choice
#Show on simplest method (fixed amount of traits).
*gosub show_chars_even_simpler
#Show on simpler method (listed).
*gosub show_chars_simpler
#Show on more complex method (dynamic sentence; good luck fixing the spaces).
*gosub show_chars
#Quit.
*finish
*choice
#Search trait in a character.
Type the ID of the character you want to search. (From 1 to ${char_quantity})
*input_number search_id 1 char_quantity
Now type the name of the trait to see if ${char[search_id][1]} has it.
*input_text search_trait
*gosub search_trait_in_character search_id search_trait
The trait "${search_trait}" was @{search_result located for character ${char[search_id][1]} at slot ${search_match_slot-1}|NOT located for character ${char[search_id][1]}}.
#Quit.
*finish
*goto finishing
*comment =============SHOW CHARACTER TITLE===============
*label show_title
==================
*line_break
${char[counter][1]}'s traits (Character id: ${counter})
*line_break
==================
*return
*comment =============SHOW CHARACTERS EVEN SIMPLER===============
*label show_chars_even_simpler
*temp counter 0
*label show_chars_even_simpler_loop
*set counter + 1
*if (counter > char_quantity)
*return
*gosub show_title
${char[counter][2]}, ${char[counter][3]} and ${char[counter][4]}.
*goto show_chars_even_simpler_loop
*comment =============SHOW CHARACTERS SIMPLER===============
*label show_chars_simpler
*temp counter 0
*temp trait_counter 2
*label show_chars_simpler_loop
*set counter + 1
*if (counter > char_quantity)
*return
*gosub show_title
*label show_chars_simpler_traits_loop
*if (trait_counter > "${allowed_traits+1}")
*goto show_chars_simpler_loop
-${char[counter][trait_counter]}
*line_break
*if (trait_counter > allowed_traits)
*set trait_counter 2
*goto show_chars_simpler_loop
*else
*set trait_counter + 1
*goto show_chars_simpler_traits_loop
*comment =============SHOW CHARACTERS===============
*label show_chars
*temp counter 0
*temp trait_counter 2
*label show_chars_loop
*set counter + 1
*if (counter > char_quantity)
*return
*gosub show_title
*label show_chars_traits_loop
*if (trait_counter > "${allowed_traits+1}")
*goto show_chars_loop
${char[counter][trait_counter]}
*if (trait_counter = "${allowed_traits-1}")
,
*elseif (trait_counter > allowed_traits)
.
*set trait_counter 2
*goto show_chars_loop
*else
${space}and
*set trait_counter + 1
*goto show_chars_traits_loop
*comment =============RANDOMIZER===============
*label randomizer
*temp new_trait 0
*temp char_counter 1
*temp trait_counter 2
*label randomizer_loop
*temp proceed false
*rand new_trait 1 trait_quantity
*if (char_counter > char_quantity)
*return
*else
*gosub check_existent char_counter new_trait
*if (trait_counter > "${allowed_traits+1}")
*set char_counter + 1
*set trait_counter 2
*goto randomizer_loop
*else
*if (proceed)
*set char[char_counter][trait_counter] trait[new_trait]
*set trait_counter + 1
*goto randomizer_loop
*else
*goto randomizer_loop
*comment =============CHECK EXISTENT TRAIT===============
*label check_existent
*params char_to_check trait_being_added
*temp check_counter 1
*label check_existent_loop
*set check_counter + 1
*if (check_counter = "${allowed_traits+1}")
*set proceed true
*return
*else
*if ("$!!{char[char_to_check][check_counter]}" = "$!!{trait[trait_being_added]}")
*set repeated_traits + 1
*set proceed false
*return
*else
*goto check_existent_loop
*return
*comment ===============SEARCH TRAIT IN CHARACTER=================
*label search_trait_in_character
*params character_id trait_to_search
*set search_result false
*temp search_count 1
*label search_trait_in_character_loop
*set search_count + 1
*if (search_count <= "${allowed_traits+1}")
*if ("$!!{char[character_id][search_count]}" = "$!!{trait_to_search}")
*set search_result true
*set search_match_slot search_count
*return
*else
*goto search_trait_in_character_loop
*return
The script uses arrays for the trait list and to store the traits each character has. The character info is stored in the array and it has 4 indexes for each character. Index 1 is the name, 2, 3 and 4 are the first, second and third traits respectively.
If you want to allow more traits on a character it’s simple and the code accomodates for it, simply add a new index for all characters like:
*create char_1_5 ""
*create char_1_6 ""
*create char_1_7 ""
This will create 3 more trait slots for character number 1, which in that preset I sent is Michelle. You need to add these _5, _6 and _7 entries for all characters so that everyone can receive new traits. After that you change the variable allowed_traits
to 6, since now everyone will have 6 trait slots.
If you want to add more traits, simply add more like this:
*create trait_21 "Ambitious"
*create trait_22 "Erudite"
*create trait_23 "Trusting"
*create trait_24 "Zealous"
*create trait_25 "Pilgrim"
This will add 5 more traits to the trait pool. After this you change the trait_quantity
variable to 25 and now 25 traits are possible.
For more characters it’s similar, simply add more character entries:
*create char_11_1 "Ralph"
*create char_11_2 ""
*create char_11_3 ""
*create char_11_4 ""
Make sure to create as many trait slots as the number of traits you decide each character to have. Then you change the char_quantity
to reflect the amount of characters.
Now to actually make this useful, let’s see how you could check if a character has a particular trait.
The simplest way to do it would be to check each slot and see if it matches something you want to search on it, but this way would become quite long if you had a lot of trait slots. A better way to search to see if a character has a particular trait is to use a function that loops through the entire array in search of it. I added one at the very bottom of the file. To use it, you simply call:
*gosub search_trait_in_character ID_OF_THE_CHARACTER TRAIT_TO_SEARCH
So let’s say you want to search if Erica (id 4 in the example I’ve made) has the trait Shy. You would use the id as the first parameter (in this case 4) and then Shy as the trait to search it.
*gosub search_trait_in_character 4 "Shy"
This will search for the trait in Erica’s trait slots and will switch a variable called search_result
to either true or false if it has located something or not. You can then right under it have a conditional to do whatever you want.
*gosub search_trait_in_character 4 "Shy"
*if (search_result)
Erica is shy!
*else
Erica is NOT shy!
This is how to fiddle with the trait randomizer. If you have any questions or want to know how to do other things with it, let me know and I can help. If you want I suggest you add this into it’s own project or startup file so that you can try a bit of it without trying to fit it inside your game first.
Let me know if there are errors as well.
Maybe I’m too new to this, but that was very over my head. I feel like if I had someone personally adding code into my game where I didn’t have to deal with it - this would work fine. But because I have to personally deal with this code, not just in this one scene, but in many other scenes where traits are assigned…I don’t think I can do it.
I’m a hands on person. But I literally don’t even know what part of your code to copy into mine. It needs to have its last *goto be *label next. The traits need to be named matchtrait1, matchtrait2, matchtrait3. I need it to have no page breaks. In my code currently, as soon as you choose #Random it randomizes many different things (including traits) and the next thing it loads is the results page.
I know you broke it down into more simple code for my own sake, but I can’t even visually follow it. I don’t even see what you did to not repeat traits.
Thank you for taking all that time in putting it together. If you can make it any more adapted to my own code, that would make it much more readable for me. I need to know what exactly to copy and paste, what to rename…etc. Seriously thank you for taking the time. Feel free to ignore this, as all your hard work has gone over my head and I am sorry for that.
I think the best thing to do here is to first of all sit back and see which traits are needed.
As these are for NPCs coding down the line would be so. Much. Worse.
The basic mechanics shown in this threat are good, but i think coding and writing wise you’ll be better off assigning traits to characters beforehand and not at random.
Take the word from someone who has the results of a cooking contest show be random each playthrough