# *Rand values (traits) repeating twice help

This is hard for me to even try to explain. I’m running into problems when coding a randomized trait system. Every person in my game has three randomized traits. The problem I’m having is the traits overlapping. An example would be: They are Compassionate, Loyal, Compassionate. Obviously, I don’t want this.
I feel like I’m drowning in code. This is what I’ve been doing to try to fix the problem, but if any other traits are already listed they will still repeat twice. I don’t know how else to explain it. I’m trying to fix it with *elseif. The traits are in startup like this: matchtrait1, matchtrait2, matchtrait3.

*elseif (matchtrait3=1) and (matchromantic= true)
*rand matchtrait3 2 4
*if (matchtrait3=2) and (matchfertile = false)
*set matchtrait3 “fertile”
*set matchfertile true
*if (matchtrait3=3) and (matchcompassionate = false)
*set matchtrait3 “compassionate”
*set matchcompassionate true
*if (matchtrait3=4) and (matchloyal = false)
*set matchtrait3 “loyal”
*set matchloyal true

Normally:

*line_break
*rand matchtrait1 1 4
*if (matchtrait1=1) and (matchromantic = false)
*set matchtrait1 “romantic”
*set matchromantic true
*if (matchtrait1=2) and (matchfertile = false)
*set matchtrait1 “fertile”
*set matchfertile true
*if (matchtrait1=3) and (matchcompassionate = false)
*set matchtrait1 “compassionate”
*set matchcompassionate true
*if (matchtrait1=4) and (matchloyal = false)
*set matchtrait1 “loyal”
*set matchloyal true
*line_break

2 Likes

Could you edit your post to format the code? Add three ``` above and below it. It makes spotting stuff easier.

I’m relatively new to the code, just as a warning.

Are there only four traits total? With three always being selected? Because if so, you would be able to make it simpler by sort of reversing the process. Instead of having a random number for each trait that’ll be assigned, you could just have a single random number for the trait not assigned.

``````*temp not_match 0

*rand not_match 1 4

*comment 1 = not romantic, set everything else to true
*if (not_match = 1)
*set matchtrait1 “fertile”
*set matchfertile true
*set matchtrait2 “compassionate”
*set matchcompassionate true
*set matchtrait3 “loyal”
*set matchloyal true
*comment 2 = not fertile, set everything else to true
*if (not_match = 2)
*set matchtrait1 “romantic”
*set matchromantic true
*set matchtrait2 “compassionate”
*set matchcompassionate true
*set matchtrait3 “loyal”
*set matchloyal true
etc...
``````

There are only four traits for now because I was testing if it would work. There are many more traits. Hence my feeling of drowning in code.
Three traits will always be selected from a random set of traits. Maybe I’m just not in my logic brain…the whole “not_match” thing confused me a bit.

It’s harder to use what you advised because of the fact that I will have around 20+ traits to choose from.

1 Like

I forgot the quotes…but just looking at all that code makes my head hurt. Idk what I’m doing. Haha

1 Like

So, since there are only 3 chosen traits vs. 20+ possible traits, it might be easier to deal with repeated values before setting traits. That means checking the values of matchtrait1, matchtrait2, and matchtrait3 against each other to make sure they are all unique. I wrote a quick example below, which should (in theory) always assign unique numbers to the variables.

``````*temp matchtrait1 0
*temp matchtrait2 0
*temp matchtrait3 0

*temp matchromantic false
*temp matchfertile false
*temp matchcompassionate false
*temp matchloyal false

*rand matchtrait1 1 4
*rand matchtrait2 1 4
*rand matchtrait3 1 4

*label check_trait_02
*comment this label checks to see if matchtrait2 is the same value as either matchtrait1 or matchtrait3, if it is, it sends it to "reset_trait_02," which will reset the value, then return here and check again. Once matchtrait2 has a unique value, it will continue on to "check_trait_03" which repeats the same process for matchtrait3
*if (matchtrait2 = matchtrait1) or (matchtrait2 = matchtrait3)
*goto reset_trait_02
*else
*goto check_trait_03
*label check_trait_03
*if (matchtrait3 = matchtrait1) or (matchtrait3 = matchtrait2)
*goto reset_trait_03
*else
*goto set_final_traits
*label set_final_traits
*comment this is where you set your traits
*if ((matchtrait1 = 1) or ((matchtrait2 = 1) or (matchtrait3 = 1)))
*set matchromantic true
*if ((matchtrait1 = 2) or ((matchtrait2 = 2) or (matchtrait3 = 2)))
*set matchfertile true
*if ((matchtrait1 = 3) or ((matchtrait2 = 3) or (matchtrait3 = 3)))
*set matchcompassionate true
*if ((matchtrait1 = 4) or ((matchtrait2 = 4) or (matchtrait3 = 4)))
*set matchloyal true
*comment etc...
Traits: @{matchtrait1 romantic|fertile|compassionate|loyal}, @{matchtrait2 romantic|fertile|compassionate|loyal}, and @{matchtrait3 romantic|fertile|compassionate|loyal}.
*finish

*comment this is the reset section where variables with repeated values are sent
*label reset_trait_02
*rand matchtrait2 1 4
*goto check_trait_02
*label reset_trait_03
*rand matchtrait3 1 4
*goto check_trait_03
``````
2 Likes

I truly appreciate all the work you put into commenting on this post. That’s a good idea to say *if matchtrait1 = matchtrait2. I hadn’t thought of that! I’m going to try to figure out how to include what you said into my code and see what happens. Thank you! I’ll let you know how it goes.

3 Likes

All the *gotos and *label checks made my Firefox crash I think. I’ve never had it crash. lol. I think I overloaded it. So…now I’m pretty stuck. It was a great idea but now idk what to do. Maybe sending it to another scene would help, so it doesn’t get overloaded?

2 Likes

Usually crashing means there is a loop somewhere.

Try running randomtest with a single iteration?

How do I run a single iteration? I rarely use the autotest, quicktest, randomtest stuff. I have little idea how to work them. I test everything through firefox scene by scene.

1 Like

So…I guess if it’s looping, it’s never making it to *label matchcontinue. You don’t have to rewrite it, but what can I do to make it not loop and still not repeat traits?

1 Like

open up the browser.
go to open file -> open randomtest.html -> set iterations to 1 and check ‘show full text’

1 Like

Your label trait3check produces a loop. One of conditions is matchtrait3=matchtrait3. Also, I’d suggest to put a temporary *ending after label matchcontinue to make sure it doesn’t skip off to another loop.

1 Like

Like Jumo said, changing “trait3check” fixes the loop, but there are still problems. Running through it each time ends up giving matchtrait1 a string, matchtrait2 a number between 1 and 4, and matchtrait3 stays at 0 every time.

Just to be sure, are matchtrait2/3 assigned random values before the text you have, or is what you posted the entirety of it? If random values are not assigned at the start, adding them in will prevent matchtrait3 from staying at 0.

Because you’re setting the matchtrait1 to a string but still checking against it for a number between 1 and 4, that means that matchtrait2/3 have be the same value as matchtrait1. Leave out all of these-

``````*set matchtrait1 "romantic"
*set matchtrait1 "fertile"
*set matchtrait1 "compassionate"
*set matchtrait1 "loyal"
``````

-until the very end.

It should work at that point. Under the label “continuematch,” you just need to set the values of matchtrait1/2/3 to strings-

``````*if (matchtrait1 = 1)
*set matchtrait1 "romantic"
*comment ect...

*if (matchtrait2 = 1)
*set matchtrait2 "romantic"
*comment ect...

*if (matchtrait2 = 1)
*set matchtrait3 "romantic"
*comment ect...
``````

If you wanted to cut it down further, you could probably take out all of these-

``````and (matchromantic = false)
and (matchfertile = false)
and (matchcompassionate = false)
and (matchloyal = false)
``````

-and everything under the labels “trait1reset” and “trait1check”, as well as this check in the first section-

``````*if (matchtrait1 = matchtrait2) or (matchtrait1 = matchtrait3)
*goto trait1reset
``````
1 Like

Thank you! I didn’t even notice the typo!

1 Like

Is there a way to get it to test certain scenes?

1 Like

I removed the loop in trait3check, what I sent was the entirety (which made me realize I forgot to even give trait2 or trait3 a value before the checks or resets. I’ve rewritten this so many times, it’s easy to forget things. - sigh -
I moved trait1 *set stuff until the end of the *sets, before the trait checks or resets. I removed trait1 reset and checks.
I guess I’m not sure what you meant by “until the end” because now it runs but it sets trait1 as a number.

That was often a problem before when running the random assignment over and over again, is not only might it repeat itself, it might turn into numbers. How the heck am I supposed to figure this out with 20+ traits? lol! I’m so lost.

no, just the whole thing.

Mhnn… so, you want to assign three traits with one of four possible ones at random, right? (thinking about if there isn’t an easier or at least less loop-prone way)

I would love there to be an easier way.

1 Like

let’s see.

so, you have romantic, fertile, compassion and loyal, right?
are there any other values assigned not seen here?
as in ‘trait1 get a higher value than 2 and 3’?