Ultimate Noob Coding

Very quick thoughts.
I presume the epilogue text uses IF to see which is higher and displays the relevant text? You could have a final ELSE which either displays a default or uses RAND to select any of the texts that meet the criteria of bei g equal to the highest.

Does your code not have a highest stat value at all times though? Presumably as soon as one stat gets a value, your code will set it as the highest. That will then change over the course of the game. If at the end of the game there are two stats tied, then the highest stat will be whichever became the highest first? As the second one wasnt higher and didnt alter the variable.

2 Likes

If these checks are part of the same logic, you should use elif instead of independent if statements. And like @Sinnie said add a final else.

If you are 100% sure the game can only be in one of these states, than instead of adding an else to the end, just replace the final elif for an else.

When you do this, the logic will always pick the first that matches and only the first.


CSLib has utilities for calculating the maximum number in a list. You might be interested.


Iā€™ve posted a solution for checking the maximum value in an list before. You might be intereted:

2 Likes

Change > to >=.

Change ifs to elseifs and an else.

Thatā€™s your cheapest, simplest answer!

2 Likes

Iā€™m going to bed in a few minutes, but Iā€™ll take a look tomorrow and see if I understand the problem (at a first glance it should always work by picking the first highest stat it encounters, in the oder of the ifs,but Iā€™m prolly missing something).

The first if is redundant because you initialize it to intimidate so it does nothing.

2 Likes

Simple is good. Going to try this out. Thanks to all of yā€™all.

2 Likes

I kind of solved something like that by checking equals before checking whoā€™s greater than.

For my dice game, if all tie then thereā€™s no need to check if someone wins, and if thereā€™s a tie and no one got a better score then thereā€™s a tie and no one wins.

There are 5 players in total, so first I check ties between 2, then 3, then 4 and finally 5. That alone are like 200 lines of code, but this one is maybe a little bit more complex cause it determines if thereā€™s a winner above the ties.

2 Likes

Ok, Iā€™ve run this code in a test project and it always picks a max. Are you sure that this is the reason why your epilogue is failing to trigger?

In a nutshell, what your code does as it is now is that it favors Intimidate if all other stats are equal, Inspire if it is highest and equal to motivate and entertain, etc.

Do you have 4 endings (1 for each stat) or more than 4 depending on the max stat combinations?

2 Likes
Through your
    *if (Highest_stat_type = Intimidate)
        reliance on brutality and fear tactics,
    *if (Highest_stat_type = Entertain)
        magnetic personality,
    *if (Highest_stat_type = Motivate)
        ability to push your people to do better while touting the value of the traditions in place,
    *if (Highest_stat_type = Inspire)
        daring rhetoric of change, which admittedly loses its luster as time marches on and you remain in power as a monarch,
you retain control of this kingdom for longer than you could have imagined.

This is the code. During a CSIDE playtest, it went straight from Through your to you retain control. Skipped all options.

It was an odd playthrough, in that I chose to overthrow Rod but ended up preventing the whole revolution and leaving him in. Which means this text never should have been visible but I had not yet accounted for that issue since Pacifist is a rare achievement (or at least, it should be). That part I did fix, but this bit with the highest stat was more complex.

Another question while I am prepping the files to be resent: how do you insert an image into the story? Never had to before, but I have cover art for both Cinderella and the prince, and since we are mostly using the Cinderella one for promo stuff I thought a good use of the dual images would be having them show up after the person picks which character they will play as.

1 Like

With the command *image, then align to left, right, center, and then if you want a description for when the image canā€™t be shown for some reason, or for visually impaired people.

*image wolf.png center A lone, mangy wolf howling at the moonlight.

I think thereā€™s another command *text_image or something like that, but I canā€™t find the documentation.

2 Likes

That code will never work because Highest_Stat_Type is a string and you are essentialy comparing a string to a number, you have to use quotation marks for it to work, like this:

The reason why you did not spot this error is that you also have variables named like that and quick test / random test did not detect the compilation failure. Iā€™m going to assume you are not a coder by profession (I apologize if I am mistaken) and share with you a little secret of the trade: you will always make mistakes because you are human and itā€™s important when writing code to put yourself in a position where you can spot mistakes easily/ make it hard to make mistakes in the first place.

When you are using ā€œtypeā€ variables where you want to distinguish between discreet scenarios (in your case what is the highest type) I recommend you use numbers instead of strings. The reason for this is that if you use strings, you are potentially inviting typo errors.

For example,

*if (Highest_stat_type = ā€œIntimidateā€) ā†’ if you misspell ā€œIntimidateā€ to ā€œIntiimidateā€, you will have a hard time finding the error.

Instead, you can do something like this

Code
*comment -1 - Unitinialized
*comment 0 - Intimidate
*comment 1 - Entertain
*comment 2 - Motivate
*comment 3 - Inspire
var Highest_stat_type -1

...

*if Intimidate > Highest_stat
    *set Highest_stat_type 0
    *set Highest_stat Intimidate

*if Inspire > Highest_stat
    *set Highest_stat_type 1
    *set Highest_stat Inspire 

*if Motivate > Highest_stat
    *set Highest_stat_type 2
    *set Highest_stat Motivate 
    
*if Entertain > Highest_stat
    *set Highest_stat_type 3
    *set Highest_stat Entertain 
    
*return

...

*if (Highest_stat_type = 0)
      reliance on brutality and fear tactics,
  *elseif (Highest_stat_type = 1)
      magnetic personality,
  *elseif (Highest_stat_type = 2)
      ability to push your people to do better while touting the value of the traditions in place,
  *elseif (Highest_stat_type = 3)
      daring rhetoric of change,
*else
   *comment keep this line only in the alpha/beta stage
   Initialization error in highest stat check area, please contact the author.

A slightly better way of doing is this when they will add autocomplete to CSIDE (when you start writing a variable the editor will suggest variable names you previously declared) would be this:

Code
var Highest_stat_Int 0
var Highest_stat_Ent 1
var Highest_stat_Mot 2
var Highest_stat_Insp 3

var Highest_stat_type -1

...

*if Intimidate > Highest_stat
    *set Highest_stat_type Highest_stat_Int
    *set Highest_stat Intimidate

*if Inspire > Highest_stat
    *set Highest_stat_type Highest_stat_Insp
    *set Highest_stat Inspire 

*if Motivate > Highest_stat
    *set Highest_stat_type Highest_stat_Mot
    *set Highest_stat Motivate 
    
*if Entertain > Highest_stat
    *set Highest_stat_type Highest_stat_Ent
    *set Highest_stat Entertain 
    
*return

...

*if (Highest_stat_type = Highest_stat_Int)
      reliance on brutality and fear tactics,
  *elseif (Highest_stat_type = Highest_stat_Ent)
      magnetic personality,
  *elseif (Highest_stat_type = Highest_stat_Mot)
      ability to push your people to do better while touting the value of the traditions in place,
  *elseif (Highest_stat_type = Highest_stat_Insp)
      daring rhetoric of change,
*else
   *comment keep this line only in the alpha/beta stage
   Initialization error in highest stat check area, please contact the author.

The latter example, even though it takes longer to write has the advantage that if you decide to change values in the future, you change them only in one place and avoid errors that would appear by forgetting/missing places where the change should propagate.

In both examples, itā€™s less error-prone because when you read the code, you have eliminated the source of error for typos and you will be more careful when writing the code because you have to check what those numbers mean in the comments and you are less likely to write on auto-pilot. (More modern languages have other more elegant ways of doing this, but they are not available in Choice Script so we have to make do with what we have).

I do not recommend implementing this best practice now because your game is already in queue and it might break other things, but I recommend you try it on your next project. Whenever you are writing code, think about ā€œHow can I make it easier for me to spot errors?ā€

2 Likes

Excellent catch. I had that code without quotes a bunch of places, too. I wonder why it never shows up that the text that they block off is unseen. In any case, I have it fixed and after a little more testing and the addition of the images, Iā€™ll send off the new files.

As for not being a coder, thatā€™s an offensive assumption. And by offensive I mean highly accurate. Iā€™m an auditor by trade, and prior to coming here five years ago hadnā€™t touched a line of code since I was rejiggering the TI-83 games my genius friend made from scratch in high school around the turn of the century (and even then, I was never messing with the code itself, just changing what I now know to be the variables so that his Mega Man game suddenly became a Dragon Ball Z one). And really, my solution going forward will be to have subroutines even less whenever possible. I like to keep things simple, and itā€™s worked moderately well so far. In this place, there are those who are gamemakers first and those who are writers first. Iā€™m definitely more in the latter camp, at least to the extent I qualify for either.

5 Likes

Hi everyone! Figured Iā€™d post my question here, sorry if it is somewhere else though. Would it be possible to have several relationship stats combine easily into one larger stat? For instance say three people are the leaders of this faction but since theyā€™re not ROā€™s I could easily just hide their individual relationship stat with the MC from the stat screen but have their combined stats show as a whole of their attitude towards the MC.

ex: while npc[1] = 80, npc[2] = 40, npc[3] = 65, thatā€™s a total 180/300 max = the faction would be at 60% but the individual characters would still have the relationship they have with MC. Just hidden from players because theyā€™re like background npcs mostly.

I just wanted to know if it was possible, if it would break fairmath, or if it would be too convoluted with the *create_array command.

1 Like

With fairmath I think you only can go up to 100, so a solution would be to add up all 3 relations and divide them by 3 to get the average, just like your example, (80+40+65) /3 = 61.66, then you can use the *round command if you like to.

2 Likes

Oh awesome! Iā€™ve never heard of the *round command but I did find it on the cog advanced choicescript page, I will definitely have to mess around with that to see if I can fully understand it. And yea fairmath I think is made to work to make sure you donā€™t pass 100. Most of whatā€™s on the choice of games site about coding I understand easily except for a handful of things. Thank you @Loudbeat!

2 Likes

I cannot believe that searching for ā€œ$!!ā€ in this thread actually got me the right answer to my question. Incredible work from four years ago, Szaal.

I wanted to check if a player got a code right, but I wanted it to work regardless of their capitalisation in *input_text. I wasnā€™t sure how to do it, but Iā€™ve now figured it out, and it looks something like this!

*input_text solution

*temp cap_solution
*set cap_solution "$!!{solution}"

*if (cap_solution = "WEED")
  hashtag 420

So, if I type ā€œwEeDā€ into the text box, I still get the answer right. Great!

Edit: Looking at further replies I could probably shorten this to:

*input_text solution
*if ($!!{solution} = "WEED")
  hashtag 420

However! I donā€™t want to do it that way, for mysterious reasons.

3 Likes

Weed is not always the solution bro, Jesus loves you the way u are, whithout anything clouding your mind! (Unless u are hasta, in this case Jesus loves u even with the clouds in your head!)

Sorry for the Bad Religion (great band though) joke! Couldnā€™t resist! :smiley:

Wait, what this ā€œ$!!ā€ Do? Convert all the content in the adrss to an upper case equivalent??

I was kinda looking something like that a couple days ago. Iā€™ve been trying to write a function that upon reading a word always pile it inside a string accordingly with the alfabetical order ā€¦ the difference between the upper and low case of a same letter was making me confused.

2 Likes

Typing $!{variable} will make it so the first letter is capitalised. Using two exclamation marks capitalises the whole word. E.g:
$!{nesquik} = Nesquik
$!!{nesquik} = NESQUIK

4 Likes

You can find other variable formatting commands here

2 Likes

Is there a way to have the player go to a different chapter than another player?

For example, if a chapter ends up being completely different depending on the characters backstory, how would you go about that?

I tried the ā€œ*If ___ *else___ā€ command, but it wouldnā€™t let me put in any choices. It only worked if it was just text

1 Like

Put a goto in the if-else, and the choices and whatnot in the label you direct from the goto.

1 Like