It is indeed that easy.
*rand dieroll 1 99
*set dieroll +stat
You could also keep the stats separate while still getting its sum.
*rand dieroll 1 99
You rolled ${dieroll +stat} (dieroll: ${dieroll}, stat: ${stat})
It is indeed that easy.
*rand dieroll 1 99
*set dieroll +stat
You could also keep the stats separate while still getting its sum.
*rand dieroll 1 99
You rolled ${dieroll +stat} (dieroll: ${dieroll}, stat: ${stat})
Is there a way to get choicescript to select the highest (or lowest) of a number of variables - apart from the obvious way of lots of *if ((x > y) and (x > z)) type bruteforce code
CS donāt have built-in command to find highest or lowest value from a set of variables. The good thing, at least, is that you can build your own code and use that on multiple places, even on different projects, once you get the subroutine done.
thanks,
another question: Is it possible to modify the text of a choice itself based on a variable?
Example, I have a standard choice
*choice
*selectable_if (action_count <= 3) #Do something.
*set action_count + 1
[text]
is it possible to modify the ā#Do somethingā based on the value of the variable: āaction_countā within the choice text itself?
I am aware I can work around this with something like:
*choice
*if (action_count <= 3)
#Do something.
*set action_count + 1
[text]
*goto somewhere_else
*if (action_count > 3)
*selectable_if (action_count <= 3) #You are too tired to do something.
*finish
but it feels clumsy to have to do it in pairs.
The Multireplace function should be able to handle it. You could do something like this:
*choice
*selectable_if (action_count <= 3) #@{(action_count <= 3) Do something. | You are too tired to do something.}
*set action_count + 1
[text]
hmmmā¦
like
*label somename
*set result 0
*comment the label "highest" in the "number"
*comment scene will compare two variables and
*comment store the value (or name if you know how to
*comment work with pointers) in the variable "result"
*gosub_scene number highest (var_1) (var_2)
*gosub_scene number highest (result) (var_3)
*gosub_scene number highest (result) (var_4)
*gosub_scene number highest (result) (var_5)
*gosub_scene number highest (result) (var_6)
*gosub_scene number highest (result) (var_7)
*gosub_scene number highest (result) (var_8)
*gosub_scene number highest (result) (var_9)
*gosub_scene number highest (result) (var_10)
*gosub_scene number highest (result) (var_11)
The higest value is: ${result}
but
I highly sugest do it in a loop so it would be something like this:
*label somename
*set result var_1
*temp parameter ""
*temp i 1
*temp total 11
*label loop
*comment let the looping begin! (11 variables total)
*comment parameter should work as a pointer to val_x
*if (i < total)
*set parameter ("var_"&"${i}")
*gosub_scene number highest (result) ({parameter})
*set i +1
*goto loop
The higest value is: ${result}
Ta DAAAAAA!!
By the sheer power of coding I command you to return me the Highest value among these variables!
*comment number.txt
*label highest
*param
*if (param_1 > param_2)
*set result param_1
*return
*set result param_2
*return
Done!
Itād only work if you name your variables exactly āvar_123ā. What about simple āstrengthā, āagiā, āintā?
Returning the VALUE and the VARNAME itself are two different things.
But yes, as youāve shown, once you gott the system set up, you can use it anywhere you like.
Hmm. I guess if you got variables with names like āstrengthā or āagilityā or āintelligenceā you would have to point āvar_numberā to them before the loop. And in the loop make it compare the last value
Make sense?
Would using two arrays work?
* comment - In startup file ...
*create varNames[1] "Str"
*create varNames[2] "Agi"
*create varNames[3] "int"
*create varValues[1] 30
*create varValues[2] 50
*create varValues[3] 40
*create mycounter 4
* comment - In Scenes File(s)
*set i 1
*label looper
*if (i < mycounter)
The value of ${varNames[i]} is ${varValues[i]}
*set i +1
*goto looper
My memory is a bit hazy, but I think thatās not how array declaration works. But you donāt even need two arrays:
*create var_1 "str"
*create var_2 "agi"
*create str 0
*create agi 0
*label bigfinder
*set loop 0
*set looplimit 2
*set returnvar ""
*set returnval 0
*label beginloop
*set loop +1
*if {var[loop]} < {var[loop +1]}
*set returnvar "var[loop+1]"
*set returnval var[loop+1]
*goto beginloop
*elseif loop = looplimit
Your biggest stat is ${{returnvar}} scoring at ${returnval}.
If you can remember that it was ever any better, then you werenāt doing it right
ā¦
And youāre correct on both counts
I like the array thing though, because its a neat way of keeping stuff together (if only in my head). So the (full) - and now tested! - way of using two arrays (and some non-array variables, just for added fun) to do the same thing and handle where the stats are equal ā¦
*comment - in the startup file
*create varNames_1 "Str"
*create varNames_2 "Agi"
*create varNames_3 "Int"
*create varValues_1 40
*create varValues_2 10
*create varValues_3 40
*create mycounter 3
*create i 0
*create remi1 1
*create remi2 0
*create remi3 0
*create highest_val_is 0
*comment - Add more remiX - and increase mycounter - if you got more variables
*comment - In Scenes File(s)
*comment set highest value and rememberID to be first value pair (at the moment, they are highest!) ... note NOT i!
*set highest_val_is {varValues[1]}
*set remi1 1
*comment start the loop
*label looper
*set i +1
*if (i < mycounter)
*if highest_val_is < {varValues[i +1]}
*comment if new > old add new
*set highest_val_is varValues[i+1]
*set remi1 i+1
*comment Reset any earlier "ties/equals!
*set remi2 0
*set remi3 0
*goto looper
*elseif highest_val_is = {varValues[i +1]}
*comment - New val = Current Highest - check whether a tie already exists
*if remi2 !=0
*comment - we already have a tie for high value, so remember another index/item.
*set remi3 i+1
*goto looper
*comment ----- NOTE: If you have more than 3 stats, you'd add ELSEIFs here
*comment - no current tie for high value, so remember the index/item
*set remi2 i +1
*goto looper
*else
*comment highest value is still old value - do nothing
*goto looper
*comment --- Print To Screen
*if remi2 = 0
Your highest value stat is: ${varNames[remi1]} with a value of ${varValues[remi1]}
*finish
*elseif remi3 = 0
You have two highest value stats: ${varNames[remi1]} with a value of ${varValues[remi1]} and ${varNames[remi2]} with a value of ${varValues[remi2]}
*finish
*else
All three of your stats - ${varNames[remi1]}, ${varNames[remi2]}, ${varNames[remi3]} - have a value of ${varValues[remi1]}.
So, look, I know ā¦ but at the moment, itās probably safest if I stay indoors anyway
Credits:
String Stuff (āfunā, but didnāt use it): Reverse Concatenation - #9 by CJW
Arrays: Initialising arrays (and programming language implementation)
Yes this is Perfect.
I have a question. What is *delay_break
and *delay_ending
and how to use them Ā“properlyĀ“?
Itās for official use, used to timegate the story (especially for non-paid ones).
here is my new question - regarding *gosub_scene.
It seems it is not possible to *set temp variables initialised in the āmaster sceneā in a scene which has been gone to via gosub_scene. Is this true or am I missing something.
example of what I mean:
*temp big_counting 0
Hi
*gosub_scene event_1
*set big_counting + 2
*return
This spits out a non-existent error variable ābig_countingā in quicktest.
Is there something I am missing here or do variable set in a subroutines not call back to the *temp variables initialized in the āmaster sceneā. They work fine with *create variables in startup.txt.
It also spits out the ānon-existent variableā when play-testing.
edit: obviously I fixed this by just migrating those variables to the startup scene, but its slightly frustrating as it means I have even more perma-variables
Afaik they donāt, the *temp will only work for the current file.
You could pass these to the other *gosub as parameters or change them to *create for global access.
In your case, you could have a global āreturn_resultā variable that receives the result of whatever goes on in event_1. And afterwards you *set big_counting return_result
.
*gosub_scene
shouldnāt produce such error while *goto_scene
does. Simple *gosub
and *goto
also do produce the errors. Hmm.
Thank you both.
If it is like this, it seems like a limitation of choicescript itself since it seems to mean you canāt do any temporary variable modification within a subroutine. Iāve just ported those particular variables across to startup.txt as a workaround. I will just have to bear it in mind.
Maybe Iāll finally get to use that *delete command after all
Iād still advise against using *delete in almost any case, though. If anything, that command would serve nothing but adding a layer of confusion, āhave I deleted this variable? Where did I delete it?ā
CS isnāt a mandating engine as Unreal, Unity, or even RPGMaker. You can get away with hundreds of active variables without the need to clean them up every scene and so to clear up the phone/PCās memory.
ill make sure to include one, just one, *delete just for you szaal
I mean sometimes its just a good practice to delete stuff youāre not gonna use anymore. At work we do some deletions because we want to avoid memory leaks and such, not saying they might happen here but sometimes you get used to making sure you close stuff you wonāt use in case something goes wrong and they are never deleted automatically.
Yesterday I was about to do the same thing, add *delete on *temps that were just part of some specific *gosubs, I even did a *gosub just to *delete n number of temp variables passed as params. However I decided to just move them all to stuff I would use on *gosub_scene and ran to the same problem @Alice-chan had with the *temps not being modifiable on other *gosubs we got to.