Displaying a random number outcome?


#1

I am trying to make a game where the player finds clues to a person’s age throughout the game, but I want to have the number generated randomly every time so that replay value is a bit higher.

I created the below in my startup file.

*create age 25

I looked at ways to extract the numerals and stuff but when I run the game, it says there is no age varrible…

*create age “25”
*create word_length length(age)
*create last_letter age#word_length

I tried to put the *rand below the *create age, but it still says, 25, even if I put *rand 1 25.


#2

Can you copy past your actual code?


#3

I might be wrong, but you’re declaring age as a string(*create age “25”), so I think it can’t really be randomised. Perhaps that has something to do with the error.


#4

@MahatmaDagon apparently choicescript isn’t picky about strings (at least in CSIDE. News to me though).

The main thing, I’m guessing, is either the order you’re building this in (*rand must be called after game init but before you set word length).

Or the lack of specific variable in *rand. I got this code working fine:

*create age 25
*create wordlength 0
*create lastletter 0

*label start
*rand age 1 25
*set wordlength length(age)
*set lastletter age#(wordlength)
*finish

#5

I am doing everything in notepad++ because CDI is not accessible to
screen readers yet. Thanks, so if I want to tell the player the first
number after that, I just display the variables normally?


#6

Yeah. In that example,

This will tell you the age is ${age}
And this will tell you the final numeral is $[lastletter}

#7

Thanks! That helped a lot!


#8

No problem! Good luck!


#9

Is there a way I can display one number at a time? Like, if a player
looks somewhere at the right time, they will see the first digit? And if
they look somewhere else, at a different time, they will see the other
digit?

I have plans on how I want the game to end so that is why I am asking.


#10

You’d want a “time” variable, but yeah. In addition to the provided code, you’d need to

*create firstletter 0
*create time 0

and set your first letter to age#1 (or if age < 10 set it to 0 to represent the first numeral).

All you’d need then is to set the time (or raise it in increments) and use if/then statements to check

*if (time = [whatever time interval you have]) 
    ${firstletter}
   ...
   *goto somewhere_else
*elseif  time = [other time interval]
    ${lastletter}
    ...
    *goto somewhere_else
*else 
    You look, but there's nothing to be found

Then firstletter would return the first digit and lastletter would return the last digit.


#11

Oh! Thanks, but I meant like, they look in a book, or something, and
then it would automatically display the first number of the randomly
generated age. I don’t quite think depending on time alone would make
for a good game because of the randomness. Plus, I have absolutely no
idea how I would keep a clock in the inventory that changes every hour
or something but thanks for the help! I’d like to have more, physical
clues, like, if someone talks to a person and gets them to tell the
birth year or something, but I am still playing with it and your help is
much appreciated!


#12

Ahh, okay then. I was thinking you wanted to do something like ZE where time changes as you make choices ^^

You’ll end up doing the same thing, then, just with different variables (basically you’ll be laying out every one of your “if someone talks to a person…” as variables and if/then statements. So if you wanted the first number to be revealed if you’re looking at a book while holding a red scarf under the full moon, you’d create variables like

*create redscarf false

Have a sequence of choices where you’d be able to find the red scarf and yield clues to where the red scarf is at.

Then have a choice like

*choice
    #I hold the book out under the full moon.
        *if (redscarf)
            A number appears. ${firstletter}
            *goto somewhere_else
        *else 
            Nothing Happens
            *goto somewhere_else
     #I hold the book out under the noonday sun.
            Nothing happens. 
            *goto somewhere_else

Here’s the wiki page that explains the variations with this type of stuff:

If you can, check out some of the CoG/Hosted lineup and find ones that do something similar. You can look into the source code for free and purchased games on the browser, so you can see how they handle the code and get an idea of how you would execute it.


#13

Assuming the age is a 2 digit number, you can always use 2 variables to display it easily in any way you like.

For example,

*create age_ten 1
*create age_unit 1

*rand age_ten 1 9
*rand age_unit 0 9

The tens digit is {age_ten}.
The unit digit is {age_unit}
The person is {age_ten}{age_unit} years old.

Let’s say age_ten randomises to 3 and age_unit randomises to 8.
This will display as:
The tens digit is 3
The unit digit is 8
The person is 38 years old.

If you want the person to be younger, less than 50, say, you can randomise age_ten from 1 to 5 instead of 1 to 9.


#14

thanks! What forum topic would you all suggest I read for some different
variations of the stats screen? I have read the stats dev wiki several
times and my experimentation’s keep breaking the return to game option
in the stats screen. If there is audio tutorials somewhere, let me know too!


#15

Well, for general learning, I’d recommend looking at the raw codes for stats screens (when playing browser games, you just replace the url after the game’s title to /mygame/scenes/choicescript_stats.txt ) and compare it to how they look/change when you play the games themselves. You won’t want to directly copy, but you can learn quite a bit.

There’s plenty of forum posts helping others through choicescript_stats problems as well, if you look for “Stats help [whatever problems you’re having]” but I can’t really give specific recommendations without knowing the details. There’s been a lot of sticking points over the years. If you can’t find a post through the search bar, you can always open a new thread asking about specifics (better to do that then chill here; you’ll get a handful of people more comfortable with stats screens and their sticking points).

I don’t believe there are any audio/video tutorials at the moment, but then, I don’t pay attention to that. ^^ I mostly stick to the written posts.