Setting a Variable off of Many Other Variables

I’m having trouble with the title basically. Idk the proper way to code this in.

The error I’m getting is: line 255 of blah: Invalid expression at char 49, expected no more tokens, found NAMEDOPERATOR and

My code looks like this:

I kind of have multiple questions.

First off, why is my code not working here? I’m trying to use multiple variables, which are ingredients of a recipe, to make another variable (the name of the recipe).

Is there a better, faster way to do this? Or a way that works lol

There are 11 ingredients(4 pref-pro, 4 aud_sta, 3 audex) that make 48 recipes(the sig_dish variable) and I’m new to choicescript and I’d love to learn how to do something this complex efficiently.

Hopefully my post makes sense, thanks in advance if you take the time to help me!

the line the error is happening is at the if, btw

*if (((pref_pro = "beef") and (aud_sta = "noodles")) and (audex = "vegetables"))

Perhaps encasing them in parentheses like this will work.

2 Likes

okay, Ill give this a try real quick! Is there any specific logic on why the last two variables only have 2 parenthesis at the end while the first has 3 at the beginning?

From my limited understanding, multiple variables need to be enclosed in parentheses. The 1st and 2nd variables are enclosed together. The 3rd is enclosed with the first two variables that are already enclosed. Sorry if I’m not making sense. Lol

1 Like

That makes sense! There was no error when I did this, but I think the second set command is the problem now. I chose other variable (ie. pref_bro “chicken”, aud_sta “rice”) and chose vegetable to see if it was working right, and it still set sig_dish to Beef Short-blah blah even though all the variables didnt match up.

So I still don’t know completely what to do to make that work

Sorry if this is a dumb question. When you changed the conditional variables, did you also change the *set sig_dish variable? Maybe it’s still outputting Beef Short because it hasn’t been changed? Maybe you can show more of the coding so we can take a wider look.

1 Like

Not dumb at all!

I actually haven’t coded in the other variables to make other dishes, I was expecting the sig_dish not to change at all but I guess it makes sense that it would still change to beef short rib since its in the code. Ill try to implement another one and see if that fixes the problem. Thanks! Ill do that real quick then come back to say if it works or not

Okay, adding other options in did make it work! Thank you!

I don’t know if I should mark as solution though, because yes that absolutely solved my problem but if anyone has advice on how to implement something like this more efficiently then I’m open ears! EDIT: Does saying solution lock the thread or something?

This is how the code ended up looking btw. Also a sneak peek to a WIP that I’ll hopefully be able to announce soon in interest check thread :wink:

sorry for the shitty phone picture :joy:

1 Like

First off, this looks like something I would definitely play! Hope to see a WIP demo soon.

I don’t know if this makes it more efficient, but maybe you can consider using *gosub_scene?

You can create recipes.txt and enter all the recipes there like:

*label sig_dish
*if (audex = "1")
  *if (prep_pro = "a") and (aud_sta = "w")
    *set sig_dish "xxx"
  *if (prep_pro = "a") and (aud_sta = "x")
    *set sig_dish "xxx"
  *if (prep_pro = "a") and (aud_sta = "y")
    *set sig_dish "xxx"
  *if (prep_pro = "a") and (aud_sta = "z")
    *set sig_dish "xxx"
  *if (prep_pro = "b") and (aud_sta = "w")
    *set sig_dish "xxx"
  *if (prep_pro = "b") and (aud_sta = "x")
    *set sig_dish "xxx"
  *if (prep_pro = "b") and (aud_sta = "y")
    *set sig_dish "xxx"
  *if (prep_pro = "b") and (aud_sta = "z")
    *set sig_dish "xxx"
  *if (prep_pro = "c") and (aud_sta = "w")
    *set sig_dish "xxx"
  *if (prep_pro = "c") and (aud_sta = "x")
    *set sig_dish "xxx"
  *if (prep_pro = "c") and (aud_sta = "y")
    *set sig_dish "xxx"
  *if (prep_pro = "c") and (aud_sta = "z")
    *set sig_dish "xxx"
  *return

And then in your code:

*fake_choice
  #A brilliant accompanying vegetable.
    *set audex "vegetables"
    *gosub_scene recipes sig_dish
1 Like

My gosh, this looks so helpful but my newbie brain can’t wrap around it! Ill read up on gosub_scene (All ive used so far is label and goto) and study what you just sent then come back if I have any more questions :joy: thank you so much for now tho!

Wait one quick question- if I use this would it go in startup or at the top of this scene? Probably startup right?

I just edited my suggestion to show a simpler code.

That code would go to a separate .txt file. In this case, recipes.txt is the name.

You can read up on gosub_scene here.

Goodluck!

1 Like

Bro, thank you so much. This is like exactly what I was looking for, im so happy lol. Thank you!

1 Like

Here’s another approach!

*temp audex ""
*temp audex_num 1
*temp pro_num 3
*temp sta_num 1
*temp sig_dish ""

*fake_choice
    #Vegetables
        *set audex "vegetables"
        *set audex_num 1
    #Dairy
        *set audex "dairy"
        *set audex_num 2
    #Spices
        *set audex "spices"
        *set audex_num 3

*temp sig_dish_num 1
*temp sig_dish_calc 1
*temp sig_dish_calc_2 1

*comment 1-12 is the first protein, 13-24 is the second, 25-36 is the third, 37-48 is the last set.

*set sig_dish_calc (pro_num * 12)
*comment this gives 12, 24, 36, or 48

*comment for startches, starch 1 is 1-3, 2 is 4-6, 3 is 7-9, 4 is 10-12; then audex is 1, 2, or 3

*set sig_dish_calc_2 (((sta_num-1) * 3)+audex_num)
*comment this gives a value of 1 to 12

*set sig_dish_num (sig_dish_calc - (sig_dish_calc_2-1))
*comment this is 12/24/36/48 minus 0 to 11 (1 through 12 minus 1)

*comment replace the letter pairs with dish names
*set sig_dish "@{(sig_dish_num) aa|ab|ac|ad|ae|af|ag|ah|ai|aj|ak|al|am|an|ao|ap|aq|ar|as|at|au|av|aw|ax|ay|az|ba|bb|bc|bd|be|bf|bg|bh|bi|bj|bk|bl|bm|bn|bo|bp|bq|br|bs|bt|bu|bv}"

So the gist is that you’ll number each ingredient as 1-4 or 1-3. (You’ll just add another *set line like I did in the *fake_choice example).

Then, with a bit of math, you can use those numbers to create a value 1 through 48.

Once you have a unique number, then you can use multireplace to set your sig_dish variable.

This has the benefit of requiring fewer lines of code.

1 Like

This does seem more efficient than having to write over 40 lines of code, but this is another thing I need to try to wrap my brain around. I think I may go with this option though, just need time to figure it out. Thank you!

Do numbered variables not need quotation marks?

Edit: Also since theses are temp stats, I assume this would go at the top of the scene the choices are in?

They don’t because they’re numbers.

The trick will just be doing the math so that you know which value 1-48 is which dish.

As for the temp stats, as long as you put them before you use them, you’re fine. Top of the scene is safest, but not explicitly necessary.

ETA: For some of the temp stats, if you’re going to use them across scenes, you can create them in your setup file instead. I just temp all my variables when I’m testing something.

2 Likes

how do you guys make the little box things that youre putting code in? I need to make some examples that may help yall help me

Three backticks in a row to start and stop the box.

Look at the top left of your keyboard. It is usually the same key the tilde (~) is on. Three in a row makes a box. Just one makes this effect.

1 Like
*fake_choice
    #Beef
        *set pref_pro "beef"
    #Pork
        *set pref_pro "pork"
    #Chicken
        *set pref_pro "chicken"
    #Seafood
        *set pref_pro "seafood"

*fake_choice
    #Pasta/Asian Noodles
        *set aud_sta "noodles"
    #Rice
        *set aud_sta "rice"
    #Potatoes
        *set aud_sta "potatoes"
    #Bread/Pastry
        *set aud_sta "bread"

Just for a little more detailed help if youre willing, what numbers should I list my other variables? Would each variable get a unique number or would ie beef and noodles be 1 along with vegetables?

@LisHz

Edit: And honestly, this method may be more efficient but it’s sort of hurting my brain :sweat_smile: . Since this is my first IF I may go with the other method. Yes it requires more typing but I think its simple enough to pull off.

Thank you though! I may need this method down the line (or I might even have to come back and use it for the recipes anyways) so your help is definitely useful!

1 Like

Set them as 1, 2, 3, and 4. (ETA: So, yes, beef is 1, noodles is 1, and vegetables are 1; they’re different variables so it doesn’t matter if they have the same value).

The math does the work to turn the three numbers into a 1-48 value.

First, the 1, 2, 3, 4 of your protein number, sets the first calc variable at one of the 4 12s in 48 (12, 24, 36, 48).

Then, the calc_2 calculation turns 1-4 and 1-3 into 1 through 12.

starch number - 1 * 3 gives a value of 0, 3, 6, or 9.
(1-1 * 3 is 0, 2-1 * 3 is 6, etc).

Then, when you add the audex number to them, you get 1, 2, 3, 4, 5, etc.

So now you’ve got calc which is 12, 24, 36, or 48 and calc_2 which is 1 through 12.

If you just subtract one from the other, you won’t get all 48 numbers and you’ll have a zero. So you subtract 1 from calc_2 to get 0 through 11.

Now, 12 - 0 is 12, 12 -1 is 11, etc. And, 36 - 4 is 32. Etc.

See how those get you to 1 through 48?

ETA: Utterly understood! I’m just a huge multireplace stan. Plus, you did say ‘faster’ initially, so I wanted to see what I could make that wouldn’t require so many lines.

1 Like