How to use *rand?

Hi all,

Have a technical question, let’s say I’m assigining a temp or created variable openwindow.

*temp openwindow
(or *set/create openwindow in startup and variables)
*rand openwindow 1 4
*if openwindow = 1
    A bird flew infront of the window
*if openwindow = 2
    You seen a shiny thing at the garden
*if openwindow = 3
     Rain drops moisten your hands
*if openwindow = 4
     You seen your neighbour working in his yard.

So how can print openwindow results on different sections of the text besides repeating.

I want the action of openwindow repeated and do not want to copy/paste same code - to keep things neat.
I’ll use them in gosub text.

Should I think of loops with labels or another logical or simple way exist?

By the way it’s for random outcomes of sport competition actions so the example is irrelevant.

*edit note:

What I’m trying is

putting the openwindow codes under

*label openwindow 
*temp openwindow
*rand openwindow 1 4

*if openwindow = 1
    A bird flew infront of the window
*if openwindow = 2
    You seen a shiny thing at the garden
*if openwindow = 3
     Rain drops moisten your hands
*if openwindow = 4
     You seen your neighbour working in his yard.
     *goto anotheraction

And link them to the action of MC or SC

mexbursh leaned to the window and opened it.
*goto openwindow

the issue is when you are using many many variables, it’s easy to miss a point.
Also I can only link it to another label to keep the flow but it will limit the process.

So if there is a simple way to call and print them beside linking with goto commands it will simplify code logic and writing I’ll appreciate to learn.

You could have one subroutine that has

*label gosub1
*temp randomnumber
*rand randomnumber 1 4
*if (randomnumber=1)
    Random text 1. 
*elseif (randomnumber=2)
    Random text 2. 
*elseif (randomnumber=3)
    Random text 3. 
*else
    Random text 4. 
*return

And in text you could have:

A pleasant thing happened. 
*gosub gosub1
And so, the pleasant thing happened.

And you could reuse the text in the subroutine anywhere it’s appropriate. You could also have a different text file to store all the subroutines so you could use the *gosub_scene command, if you’re planning on using the same text in more than one scene file.

2 Likes

It was in gosub file as well . I’ll organize them as per your sample. Will me much more shorter and easy to review.

Thanks!

I’ll test it and post my thoughts later, it’s not suitable for all cases but some it will work.

Hi @mexbrush, please try to wrap your code in preformat tags (shift+ctrl+c) in the future, as it really helps us to see your indentation (which is crucial in ChoiceScript). I’ve edited your post above, as an example.


*label ap3moves
*if passtoken10 > 0
	*goto no11

*if passtoken11 > 0 
	*goto no10
	
*label no11

${no11name} smoothly.
*if no11mability > opgkprmability
	*goto goalfinish
		
	*if no11mability < opgkprmability
		${no11name} tried but missed
		Good save by the keeper!
	*else no11speed > opgkprspeed
		*goto goalposition
			
	
*label no10

${no10name} smoothly.
*if no10mability > opgkprmability
	*goto goalfinish
	*comment ....


	*if no10mability < opgkprmability
		${no10name} tried but missed
		Good save by the keeper!
	*else no10speed > opgkprspeed
		*goto goalposition

What I did was moving the randoms to different labels like goalfinish / goalposition.

This part is actually inside ap3move which is 3rd phase of action flow - the maturation happens if each phase randoms passes the limit I set for outcome.
For e.g. defence interception points lower than those go the ball etc.

Actually to make it consistent with story flow I decided a binary structure;
Main scene file with story based initial randoms & several results or comments consequence of random rolls consistent with the flow.

So it’s going through and back to it’s relevant gosub file - also gosub file will goto that specific scene - two way interaction.

As the story progresses the event variables has to improve so planning to have level based gosubs .( Or may be have a very systematically organized longer one - I will see depending on the need and performance stability)

So I wanted to assign randoms to each movext let say ; at the background movext random variable with it’s outcome will be able to call that random explanation and result from library(gosub or scene text etc) file.

Hope I did lay out clearly.

1 Like

I know nothing about coding but if you wanna make it more literal, you can spend it cause it’s the currency of South Africa

1 Like

I think you’re looking for Multireplace that uses @{} so it can be like this:

*label open_window
*temp seed 0
*rand seed 1 4
@{(seed) Bird.|Shiny.|Rain.|Neighbor.}
1 Like

I did some tweaking, the problem is when you have a file named gosub_2 etc you can not use gosub command so you have to go fro n back from screen to screen with goto_scene command

I tried to have a single page act for it but randoms are probably creating a mess and it simply freezes the browser.
I have dozens of randoms working for action on the event and match. (Over 1000 lines with more than half code)

So gosub and single file is not fruitull. I thought another solution will try afterwork.

Seems like I will need to do it as I did in my first writings, thinking in advance and preparing multiple use page for all events is a bit problematic - needs to go fro n back more than 12 times to story file so a repetition seems to cause problems onwards.

Repetition meaning if you have 3 games you will have to add 36 goto scene in a single file prone to mistakes on the long run .

I m green so I will appreciate seasoned ideas and comments

Solution Theory {tested partially working, WIP} : Have binary system again - instead of gosub logic It will go from and back to scene A to scene mcodes-A

I’ll copy and reuse Scene mcodes-A with different names for matcb B - matchcodes-B.txt etc.

So it will ease the system by referring to secondary file for arithmetics - do the calculations and print the result - than go back to the previous file use the randoms and go back again calculations .

So I will have the story and some randomvalues scene A and than scene mcodes-A with a lot of calculations with random

I belive when there are 50+ randoms on single scene it is crushing and freezing (If I’m not doing a mistake massively)

When I handle that I will notify from here - also be able to post my demo.