Math questions

I am trying to figure out if the following is something one can do in Choice Script:

The player develops interests which, through choices, grow or shrink over time.

  1. Is there a way to sort interests by value?
  2. Can I identify if an interest has the highest/lowest value or is among those that are?
  3. Can I average the values of all interests and then determine if an interest is above or below the average?

Thanks in advance for anyone who can help me with this or point me in the right direction.

CSLib might interest you.

But yeah, all of those seem possible, although some potentially more cumbersome to do than others, depending on how many things you are comparing.

3 Likes

I’ve replied to a similar question to find the max out of a bunch of variables recently. You can check the example code I’ve made here:

To get an average you can just add up and divide by the quantity.
This might be useful:

If you need code examples just ask but I think it’s fairly simple to do if you know basic math.

1 Like

I believe you can do so by using recursivity. the first and second ones I mean.

like:


*create return ""
*temp relationship_ana 23
*temp relationship_elsa 32
*temp relationship_hans 3
*temp relationship_sven 50
*temp relationship_troll 60

And soo…



*label compare
*params relationship_x relationship_y
*comment compare if x>y
*if {relationship_x} >= {relationship_y}
    *set return relationship_x
    *return
*else
    *set return relationship_y
    *return

then


*gosub compare ("relationship_ana") ("relationship_elsa" )
*gosub compare (return) ("relationship_hans")
*gosub compare (return) ("relationship_sven")
*gosub compare (return) ("relationship_troll")

Higest relationship: ${return}
Whose value is: ${({return})} points.

*page_break

the third one sounds like a arithmetic summ of all the relationships divided by the number of love interests.

@Nahim_Kerman Victor, Thank you! Amazing. I will try to try this today. I will then try to code it to then see how MANY #1 (highest/lowest) there are so I can then check for any particular one so I can say “This is ONE of the top ones” vs “This is THE top one”.

1 Like

Do you mean, if more than one have the same value? What I’d do is store the highest value in a “max_rel” (or somesuch) variable and then compare the relationship values to it. (Of course, you’ll then need to set the value again if some relationship value increases higher, or a relationship value decreases in a way that none are at that level anymore.)

@LiliArch Yeah. I mean if there are multiples at the top or the bottom, then I don’t think @Nahim_Kerman’s code would work to give me THE highest or THE lowest - but I think what it would return is the value of that highest and lowest, when I can then use to compare against individual ones to see if they match or not. What do you think? Is there an easier or more elegant way to code it?

Now that I remember, I hardcoded a game of dice, with 4 npc + the player, in one of my WIP. It has a way to compare winners and draws. It’s all done with choicescript.
All the code is in one of the files. You can look at it if you want to, maybe it’ll be useful for you to get inspiration, or to copy some ideas/code out of it.

@Loudbeat Yes please!

Oh sorry. here it is

The file name is twenty_up. I guess you know how to look for it…?

Well, that depends - that code gives you the (first, if multiple) relationship that has the highest value. It’s great, if you want to know what relationship it is, and you certainly can use it to get the highest value. (I also think it doesn’t take the full advantage of being recursive, but that’s another discussion.)

But if all you need is the highest value (do you need the lowest value too, or is it just highest?) it seems a lot of unnecessary work to me? To me, it seems you could just keep track of the highest value every time you change the relationship values. Not that you don’t need to iterate through every relationship in that case too, just… not every time.

But I’d have to write some test code first for that, and I wouldn’t want to give an example you don’t need.

@Loudbeat I don’t, sorry. I have only been here for a few weeks. Advice would be appreciated.

Signed, The Noob

1 Like

@LiliArch Thanks. It might make sense if I leave the realm of abstraction and explain what I am up to.

In my book you go to a museum and visit different exhibits. Each exhibit is association with a particular area of science - an Ology. Each exhibit visited raises the related Ology for that exhibit. In each hall, you are given the chance to take photos with your siblings at a limited number of exhibits. In the *choice options - when offered to be IN the photo - there are yes and no options. RIght now, if your exhibit-related Ology is HIGHER than the average then the options are (Yes, because you tend to like that type of exhibit OR No, even though you tend to like that type); I have a related one if the Ology is LOWER than the option.

What I’d like to do is replace those options if the Ology is the highest or lowest, to make it special, as in: “Of course! This one’s your favorite” or “Oh, hell no! So boring!!!”.

Does that help explain what I am looking for?

The visiting of exhibits and the taking of photos is a constant and frequent mechanic throughout the book.

Ohh my bad. I thought the function also worked on this other site too, but now I see it’s only for dashingdon.

Here is an older version. The file twenty_up.txt is there.

Katewing’s Adventures old version files

Just so you know. On the dashingdon site, you can add the word /scenes/ at the end of the link of a game and it’ll show you all the files it has. Or remove it to get the playable site of it.

edit: Don’t worry. We all started there at some point anyway.

Well, you can still see the files, you just need to point to them directly (so no peeking at everything the folder has).

So instead of scenes, you can put in scenes/startup.txt and go from there.

@Barry_Joseph I think I got the idea, yes. Of course I could have gotten it wrong. :stuck_out_tongue:

I’ll try to make up an example for you of how I’d do that, but I’ll need to test it first.

1 Like

Ohh, tricky…

Speaking of noobs, I feel like an old noob now :rofl:

Oh, I had no idea. Thanks.

Can you please pick my jaw back up from the ground? This is awesome, and massive, and currently beyond my ability to parse it out to pull out (and adapt) just the part I need.

Thank you!

1 Like

Oh, Thanks! I didn’t think it was that much honestly. I did all that even before doing any programming course :sweat_smile:

You should see what others have done here.


In any case.
The game rules are that every player makes a prediction: greater or lower than 1-to-20
or equal to 1-to-20
Each player turns a cup with one 20 dice and the closest one to the prediction wins. Just a simple game.

The code just randomizes the other player’s predictions (with some leeway) and randomizes the roll dice of everyone.
Then compares and gets if there is a true prediction, or if there are ties of 2, 3 or 4 players
Then also compares if there is any prediction closer that wins over the ties.
Then gets the winner and adds up the points to the score variables.

It might seem complex in the code, but once you split it into smaller parts it gets easier.
That’s like the basics of coding. Separate the functions into small chunks, then make it work with other small chunks and you can build big stuff without even knowing.

2 Likes

/scenes actually works on the new site too, just replace index.php with scenes. E.g.,:

https://cogdemos.ink/play/bjoseph/exit-through-the-gift-shop/mygame/scenes

DashingDon and CoGDemos.ink have slightly different URL schemes for the playable game link, but the link to the scenes list is the same.

dashingdon.com/play/USERNAME/GAME-TITLE/mygame/ VS
cogdemos.ink/play/USERNAME/GAME-TITLE/mygame/index.php

1 Like

Huh. It does not work on Loudbeat’s link (or more accurately, it gives a 404). Maybe that’s some result of older vs. newer project, or did the codebase update go live already?

1 Like