Ultimate Noob Coding

The first choice determines what the second set of choices will be but the choice 2’s answers keep replacing choice 3’s answers as well as omitting the text before it. Did I input something wrong?

Here’s an example of my code:

*create strength 10
*create agility 10
*create intelegence 10
*create charisma 10
*create gender "undetermined"
*create mx "mx"
*create name ""
Pick blah blah blah blah blah blah.
*choice1
	#Male
		*set gender "male"
		*goto gender_chosen
	#Female
		*set gender "female"
		*goto gender_chosen
	#I Don't care...
		*temp random_gender
		*rand random_gender 1 2
		*if (random_gender = 1)
			*set gender "male"
		*if (random_gender = 2)
			*set gender "female"
		*goto gender_chosen
*label gender_chosen
*if (gender = "male")
	*set mx "Dante"
*if (gender = "female")
	*set mx "Lilith"
*if (gender = "male")
	Bunch of words here.
*choice2
	#option1
		*set strength +10
	#option2
		*set agility +10
		*goto action
*if (gender = "female")
	Bunch of words here
*choice3
	#option1 
		*set charisma +10
	#option2
		*set intelegence +10
		*goto action
*label action
Well ${mx}.
*line_break
Blah Blah Blah Blah Blah.
*finish
Example
*commend
    Indent
1 Like

Welcome! For starters, there has to be a *goto after each option in a choice; it looks like you only have it under the last option in each choice. But if I choose to boost strength, I need a goto, and if I choose to boost agility, I need a goto, even if they’re the same one (which they usually would be, though they certainly don’t have to be).

1 Like

Another code question -

I have a situation where I have a number of dialogue choices (1 - 8). Choice 8 moves the scene on, choices 1-7 are dialogue loops which go back to the choice menu. 5 of the options are always visible but dialogue options 6 and 7 are contingent on previous events

It looks like this.

*label choice_loop
*choice
    *disable_reuse #Talk about A
        text
        *goto choice_loop
    *disable_reuse #Talk about B
        text
        *goto choice_loop
    *disable_reuse #Talk about C
        text
        *goto choice_loop
    *disable_reuse #Talk about D
        text
        *goto choice_loop
    *disable_reuse #Talk about E
        text
        *goto choice_loop
    *if (variable_1 = 1)
        *disable_reuse #Talk about F
            text
            *goto choice_loop
    *if (variable_2 = 1)
        *disable_reuse #Talk about G
            text
            *goto choice_loop
    #You don't want to talk about the others.
        *goto next_scene

Now the last option - to move the scene onwards I want to change the wording based on if you have exausted all other dialogue options

So if you have exausted all options it would say “There is nothing else to talk about.” but if there were still options availability you don’t want to chose it will say “You don’t want to talk about the others.”

Now I know how to do this if all other dialogue options were selectable at all times, you could just use a simple count which goes up for each dialogue choice and a check to see if the max count has been reached then change the text of the final choice depending on that, using e.g. multireplace or various other ways

But my problem is that the “max” dialogue choices in this instance range from 6 to 8 depending on previous choices. So my question is - 1) is there a way to just code a check to see if all other dialogue choices have been exhausted? and 2) if this is not possible could anyone think of a work around?

you could use a numeral temp and multireplace. (for this assume F and G can’t show up in the same playthrough)

so

*temp talkywalky 0

*label choice_loop
*choice
    *disable_reuse #Talk about A
      *set talkywalky +1
      text
      *goto choice_loop
    *disable_reuse #Talk about B
      *set talkywalky +1
      text
      *goto choice_loop
    *disable_reuse #Talk about C
      *set talkywalky +1
      text
      *goto choice_loop
    *disable_reuse #Talk about D
      *set talkywalky +1
      text
      *goto choice_loop
    *disable_reuse #Talk about E
      *set talkywalky +1
      text
      *goto choice_loop
    *if (variable_1 = 1) *disable_reuse #Talk about F
      *set talkywalky +1
      text
      *goto choice_loop
    *if (variable_2 = 1) *disable_reuse #Talk about G
      *set talkywalky +1
      text
      *goto choice_loop
    #@{(talkywalky =5) There's no one else to talk to| You don't want to talk about the others}.
      *goto next_scene

adjust the indents to your needs

unfortunatly that won’t work because the value of “talkywalk” will vary between 6 and 8 in my example.

see here:

Do #F and #G made visible by A~E, or are they triggered by condition outside of this *choice scope?

they are triggered by conditions outside of this code snippet.

The only workaround I can currently think of is to have the same variables that allow F and G to be conditioned to increase the “max count”

waaaaait what if:

*temp talkywalky 0
*temp talkywalkytrigger 5
*if variable_1 = 1
    *set talkywalkytrigger + 1
*if variable_2 = 1
    *set talkywalkytrigger + 1 

All the rest of the code here

#@{(talkywalky = talkywalkytrigger) There's no one else to talk to| You don't want to talk about the others}.
      *goto next_scene

think i might have solved it thank you all

as said, adjust things to your needs

Bit of ring rust showing up. Is there a reason why my quick and random test have stopped working? Tried to run it on my new WIP and it says Error: couldn’t open web/mygame/scenes/startup.txt. Tried it with the Parenting ones and it says the same thing.

Anyone know about the above issue? Still have not figured it out, and it’s throwing off me potentially putting up a new WIP thread today.

Not sure why this might be happening. Is it possible the files got corrupted?

Some things to consider/try if you haven’t already:

Does the problem persist with a freshly downloaded copy of CS?

Is your browser updated to the most recent version?

If you create a brand new blank game, do the tests work on that?

1 Like

They shouldn’t be corrupted; they work on CSIDE just fine.

I have never had a new version of CS. I guess I did not know that was a thing. Do you just delete all the old stuff or something?

It’s been a while since I’ve downloaded an up to date version of ChoiceScript, but I would be terribly surprised if the answer has changed: I’ve always been able to keep multiple ChoiceScript versions side-by-side, each in their own folder. I’ve never deleted any of them, and never had a conflict.

That said, your original error message (couldn’t open web/mygame/scenes/startup.txt) is almost certainly possibly due to an update in your web browser that changes the way locally hosted files (index.html, quicktest.html, randomtest.html, etc.) can load other files (startup.txt, etc.).

Download a new ChoiceScript installation, read the installation instructions three times (because they’re almost certainly different than what you’ve done with past versions), then follow the instructions and try it with the new version.

1 Like

I know it’s been a while already, but a couple of posts above, the guys were trying to figure out the best way to determine the minimum and maximum variable in a given set. So I just wanted to share my solution:

I created a subroutine that accepts as many arguments as you want and it will return the one with the highest value.

  • Name: max()
  • Signature: gosub max() arg_1 arg_2 arg_3 etc
  • Description: selects the highest value in a set
  • Arguments:
    1. arg_1: Integer: number of variables to be compared;
    2. arg_2: String: name of the variable (inside quotation marks), e.g.: “honesty”;
    3. any subsequent argument follows the pattern of the second one.
  • Return:
    1. output_1: String: name of the highest variable, the value of the variable can be retrieved with curly brakets, i.e. {output_1}
    2. output_2: Boolean: returns true if there was a tie during testing
*temp honesty 0
*temp courage 0
*temp intelligence 0
*temp influence 0

*rand honesty 0 100
*rand courage 0 100
*rand intelligence 0 100
*rand influence 0 100

*temp output_1 ""
*temp output_2 ""
*gosub max() 4 "honesty" "courage" "intelligence" "influence"

*if output_2 = false
	The stat with the highest value is ${output_1} at ${{output_1}} points.
*else
	There was a tie!


*finish
*label max()
*params
*temp test_length param[1]
*temp maxval param[2]
*temp test_index 3
*temp tie false
*if (test_length < 2)
	*return
*label max_foreach
*if ({maxval} > {param[test_index]})
	*goto max_continue
*elseif ({maxval} < {param[test_index]})
	*if (tie = true)
		*set tie false
	*set maxval param[test_index]
	*goto max_continue
*else
	*set tie true
	*goto max_continue
*label max_continue
*set test_index +1
*if (test_index <= test_length)
	*goto max_foreach
*comment return result
*set output[1] maxval
*set output[2] tie
*return

You can tweak it so that in case of a tie it returns the value of the other variable as well. But it’s never going to be perfect For example if there is a tie between three variables.

You can tweak it to return the lowest variable instead.

If testing local variables, make sure the subroutine is in the same file.

Is it possible to have variable names which contain other variables?

Example in pseudocode:

You have two people. - lets call them “alice” and “alice2”

*create alice.friendscore 10
*create alice2.friendscore 20

Whichever person is “active” is controlled by a variable

*create active_person ""

You can set either one as active

*set active_person "alice"

That would then control which variable your were setting on a scene

*set ${active_person}.friendscore + 10

This way I could have a subroutine which would be applicable for either of these two characters where I could control the variable that was being set.

Is there a way to do this?

Hi, yes!

It’s actually really cool. You need to make sure that the name of the variable you’re trying to change is completely included as a text in a different string.

*create alice_friendscore 0
*create niko_friendscore 0
*create active_friend ""
*create friendscore_modifier_text ""

The first part is to change to the active friend.

*label top

*fake_choice
	#alice
		*set active_friend "alice"
	#niko
		*set active_friend "niko"

Then you need to concatenate the active friend with the _friendscore appendix, so the complete name is the variable you wish to modify. I believe this is the only step you missed out on in your example.

*set friendscore_modifier_text active_friend & "_friendscore"

You’ll see that you can then refer to it with curly brackets (without the $ symbol) in the *set command:

*set {friendscore_modifier_text} + 10

Alice: ${alice_friendscore}
Niko: ${niko_friendscore}

*goto top

I hope I made some sense and that this helps!

2 Likes

wow, thats cool. do I need to put *if commands in curly brackets too?

e.g.

*if {friendscore_modifier_text} >= 20
    *goto scene_1
*else
    *goto scene_2

Yes.

Curly brackets are practically the same as the print syntax ${}, with the difference is $ signifies the “hey code, write down the content of the {}.”

For reference

*set miniclass "text"
*set middleclass miniclass
*set hiclass middleclass

*if (miniclass = {middleclass}) and ({middleclass} = {{hiclass}})
   ${miniclass} = ${{middleclass}} = ${{{hiclass}}}
1 Like

Thanks everyone. I managed to get it working and it is nice!

Just a heads up, as szaal is indicating, if you want to display the text/value of a variable you create in this way it has to go in the double curly brackets (or however many levels you have)

so

${friendscore_modifier_text}

will show the name of the concatenated variable e.g. “alice_friendscore”

while

${{friendscore_modifier_text}}

will show the value for alice_friendscore e.g. 20

To be honest I have no idea what @Szaal is saying. I usually just smile and wave, because most of it goes over my head. :sweat_smile:

I’ll take your word for it, though! :rose: