Randomize Stringlist Question [SOLVED]

Anonynn
30 Oct 2017, 17:40I know there is a specific way to do this without creating a mile-long "if-script". Does anyone have the time to walk me through it a little?
GetRandomize(3.0;3.2;3.4;3.6)
Or something like that?
Thanks in advance,
Anonynn!
The Pixie
30 Oct 2017, 17:49You want a list of strings to be shuffled?
sl = Split("3.0;3.2;3.4;3.6", ";")
shuffled = NewStringList()
while (not ListCount(sl) = 0) {
s = PickOneString (s1)
list add (shuffled, s)
list remove (sl, s)
}

Anonynn
30 Oct 2017, 21:23I just need to Randomize my Heights between races. Since I'm just about finished redoing my new Character Creator ^_^ I just need 1 Stringlist randomized, don't need them shuffled, just randomly picked between a set of numbers. Am I making sense xD?
For example...
human (5.0;5.2;5.4)
gnome (3.0;3.2;3.4) etc.
Anonynn.

K.V.
30 Oct 2017, 21:40Something like this? (Maybe not the entire script)
humans = NewStringList()
min = 5.0
max = 6.4
while (min<max) {
list add (humans, ToString(min))
min = min + .1
}
//msg (humans)
num = 0
HumanRacers = NewStringList()
while (not num = 3){
num = num + 1
n = PickOneString (humans)
list add (HumanRacers, n)
list remove (humans, n)
}
msg(HumanRacers)
Or do you want to randomly select one height from each group?
human = Split("5.0,5.2,5.4", ",")
yourHeight = PickOneString(human)
msg ("You are "+yourHeight+" units tall.")

Anonynn
31 Oct 2017, 01:55More the second one. I don't want it chosen by the player, I just want it randomly chosen by the game. ^_^ But yes, I just want the game (based on a race choice by the player) to choose a height for the player.
Anonynn.

K.V.
31 Oct 2017, 02:33Groovy.
Do you need more of a range in the second one?
humans = NewStringList()
min = 5.0
max = 6.4
while (min<max) {
list add (humans, ToString(min))
min = min + .1
}
yourHeight = PickOneString(humans)
msg ("You are "+yourHeight+" units tall.")
player.height = yourHeight
//or
//player.height = ToInt(yourHeight)
If I give it more of a range between min and max, it starts adding .099999 instead of point one for some reason...

DarkLizerd
31 Oct 2017, 03:12How about just a simple random number???
min = 5.0
height=GetRandomInt(0,14)/10 +min
This give you 5.0 to 6.4
or for even values:
height=GetRandomInt(0,7)/5 +min
OR...
as a function, pass 3 values (min, range, increment )
height=GetRandomInt(0,range)/increment +min

Anonynn
31 Oct 2017, 03:14Is there a more simple way? Like...
height.Stringlist
GetRandom(3.0;3.2;3.4;3.6)
^ something like that?
Anonynn.

K.V.
31 Oct 2017, 03:16I didn't know about that one, DL, but it seems to be much more efficient. 😅

DarkLizerd
31 Oct 2017, 03:23height.Split("3.0;3.2;3.4;3.6", ";") // list of heights, 4 options
sel= GetRandomInt(1,4) // Select one from list.
player.height=stringListItem (height, sel)
And if you add more heights, I think there is a "count item" command so all you would need to do is add to the list, and the program will know how many items are in your list.

K.V.
31 Oct 2017, 03:25height = 3 + "."+GetRandomInt(2,6)
msg ("You are "+height+" units tall.")
// I just added this next line on to set the attribute as a double integer, if need be:
game.pov.height = ToDouble(height)
You are 3.3 units tall.

K.V.
31 Oct 2017, 04:04I just now understand what you're wanting to do. (All my fault. You phrased it clearly.)
You want to create a string list, comprised of three double integers, and you want each string to be pretty much random.
humans = NewList()
count = 3
while (count>0) {
count = count - 1
whole = GetRandomInt(4, 6)
tenths = GetRandomInt(2, 6)
height = whole + "."+tenths
height = ToDouble(height)
list add (humans, height)
}
msg ("Humans: " + humans)
Humans: List: 6.5; 4.3; 4.4;

Anonynn
31 Oct 2017, 04:12height.Split("3.0;3.2;3.4;3.6", ";") // list of heights, 4 options
sel= GetRandomInt(1,4) // Select one from list.
player.height=stringListItem (height, sel)
Error running script: Function not found: 'height.Split'
Getting this error. :/
The height is on my player.Object as a string "unknown".
Here's an example of what I'm going for...
Player selects "Human"
if (player.gender="female") {
height.Split ("5.0;5.2;5.4;5.6;5.8;6.0", ";")
sel = GetRandomInt(1,6)
player.height = stringListItem (height, sel)
Get Height
}
else {
height.Split ("5.2;5.4;5.6;5.8;6.0;6.2", ";")
sel = GetRandomInt(1,6)
player.height = stringListItem (height, sel)
Get Height
}
Anonynn.

K.V.
31 Oct 2017, 04:17Edited: I inserted your numbers.
game.pov.height = Split("5.0;5.2;5.4;5.6;5.8;6.0", ";")[GetRandomInt(0,5)]
msg ("You are "+game.pov.height+" units tall.")

K.V.
31 Oct 2017, 04:41Check this out.
It's what I was doing mixed with what DL was suggesting:
<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Heights">
<gameid>ce90f753-d526-4666-ac44-26c0d970fa2d</gameid>
<version>1.0</version>
<firstpublished>2017</firstpublished>
</game>
<object name="room">
<inherit name="editor_room" />
<enter type="script">
heightsFunction ("human")
heightsFunction ("gnome")
</enter>
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
</object>
<function name="heightsFunction " parameters="race">
switch (race) {
case ("human") {
heights = Split("5.0;5.2;5.4;5.6;5.8;6.0", ";")
}
case ("gnome") {
heights = Split("3.0;3.4;3.8", ";")
}
default {
msg ("Something messed up.")
}
}
game.pov.height = heights[GetRandomInt(1,ListCount(heights)-1)]
msg ("You, "+race+", are "+game.pov.height+" units tall.")
</function>
</asl>
You, human, are 5.2 units tall.
You, gnome, are 3.8 units tall.

Anonynn
31 Oct 2017, 04:43[GetRandomInt(0,5)]
[GetRandomInt (0, 5) {
]
^ shows up like this in code view, which is destroying my script xD
So far I have this.
if (player.gender="female") {
game.pov.height = Split ("5.0;5.2;5.4;5.6;5.8;6.0", ";")
}
else {
game.pov.height = Split ("5.2;5.4;5.6;5.8;6.0;6.2", ";")
}
Anonynn.

K.V.
31 Oct 2017, 04:58Did you move things around?
What did you paste in before Quest changed it?
What I'm really doing there is:
list = Split("1;2;3", ";")
random_integer = GetRandomInt(0,5)
attribute = list[random_integer]
So, if the random_integer is 1, it would pull the first string from the list:
list[1]
Same thing as ListItem(list, 1)
...or:
game.pov.height = ListItem(Split("5.0;5.2;5.4;5.6;5.8;6.0", ";"), GetRandomInt(0,5))
msg ("You are "+game.pov.height+" units tall.")
Here's a more complicated, fancy way to feed it 2 parameters:
<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Heights">
<gameid>ce90f753-d526-4666-ac44-26c0d970fa2d</gameid>
<version>1.0</version>
<firstpublished>2017</firstpublished>
</game>
<object name="room">
<inherit name="editor_room" />
<enter type="script">
heightsFunction ("human", game.pov)
heightsFunction ("gnome", gnome)
</enter>
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<object name="gnome">
<inherit name="editor_object" />
<look><![CDATA[The gnome is {gnome.height} units tall.<br/>]]></look>
</object>
</object>
<function name="heightsFunction" parameters="race, obj">
switch (race) {
case ("human") {
heights = Split("5.0;5.2;5.4;5.6;5.8;6.0", ";")
}
case ("gnome") {
heights = Split("3.0;3.4;3.8", ";")
}
default {
msg ("Something messed up.")
}
}
obj.height = heights[GetRandomInt(1,ListCount(heights)-1)]
msg (CapFirst(GetDisplayAlias(obj))+", race: "+race+", height: "+obj.height+" units tall.")
</function>
<function name="newHeightFunction">
game.pov.height = Split("5.0;5.2;5.4;5.6;5.8;6.0", ";")[GetRandomInt(0,5)]
msg ("You are "+game.pov.height+" units tall.")
</function>
</asl>

Anonynn
31 Oct 2017, 04:59I put it like this
game.pov.height = Split("5.0;5.2;5.4;5.6;5.8;6.0", ";")
[GetRandomInt(0,5)]
^ that's all I did. Are they supposed to be on the same line?
Anonynn.

K.V.
31 Oct 2017, 05:01if (player.gender="female") {
game.pov.height = ListItem(Split ("5.0;5.2;5.4;5.6;5.8;6.0", ";"), GetRandomInt(0,5))
}
else {
game.pov.height = ListItem(Split ("5.2;5.4;5.6;5.8;6.0;6.2", ";"), GetRandomInt(0,5))
}
msg ("You are "+game.pov.height+" units tall.")
...or...
if (player.gender="female") {
game.pov.height = Split("5.0;5.2;5.4;5.6;5.8;6.0", ";")[GetRandomInt(0,5)]
}
else {
game.pov.height = Split ("5.2;5.4;5.6;5.8;6.0;6.2", ";")[GetRandomInt(0,5)]
}
msg ("You are "+game.pov.height+" units tall.")
...or...
female = Split("5.0;5.2;5.4;5.6;5.8;6.0", ";")
male = Split ("5.2;5.4;5.6;5.8;6.0;6.2", ";")
if (player.gender="female") {
game.pov.height = female[GetRandomInt(0,5)]
}
else {
game.pov.height = male[GetRandomInt(0,5)]
}
msg ("You are "+game.pov.height+" units tall.")
...or...
female = Split("5.0;5.2;5.4;5.6;5.8;6.0", ";")
male = Split ("5.2;5.4;5.6;5.8;6.0;6.2", ";")
int = GetRandomInt(0,5)
if (player.gender="female") {
game.pov.height = female[int]
}
else {
game.pov.height = male[int]
}
msg ("You are "+game.pov.height+" units tall.")
...or...
female = Split("5.0;5.2;5.4;5.6;5.8;6.0", ";")
male = Split ("5.2;5.4;5.6;5.8;6.0;6.2", ";")
int = GetRandomInt(0,5)
if (player.gender="female") {
game.pov.height = ListItem(female, int)
}
else {
game.pov.height = ListItem(male,int)
}
msg ("You are "+game.pov.height+" units tall.")
The part in the []
telling Quest the index number of the string we want. It being on another line is what got you.
It's the same thing as the int index
number in ListItem
(the second parameter).
ListItem (list, int index)

Anonynn
31 Oct 2017, 05:21Error running script: Error compiling expression 'Split ("5.2;5.4;5.6;5.8;6.0;6.2", ";"), GetRandomInt(0,5))': SyntaxError: Unexpected token ","; expected one of <EOF>Line: 1, Column: 39
game.pov.height = Split ("5.0;5.2;5.4;5.6;5.8;6.0", ";"), GetRandomInt(0,5))
^ is what I have.
Isn't it player.pov?
Anonynn.

K.V.
31 Oct 2017, 05:26Syntax got you. Should be:
game.pov.height = Split ("5.0;5.2;5.4;5.6;5.8;6.0", ";")[GetRandomInt(0,5)]
Yet another way to do it:
Check this one out. It's less typing:
heights = Split("5.0;5.2;5.4;5.6;5.8;6.0;6.2", ";")
if (player.gender="female") {
game.pov.height = heights[GetRandomInt(0,5)]
}
else {
game.pov.height = heights[GetRandomInt(1,6)]
}
msg ("You are "+game.pov.height+" units tall.")
NOTE: Every method I've posted has worked for me. (I promise I'm testing them before posting them.)

Anonynn
31 Oct 2017, 05:45Testing stuff; one moment :D Thank you for all your help so far! I can't check to see if it's working until other errors get resolved along the way, usually minor. It is a gigantic character creator so...it won't be too long. one more moment!
Anonynn.

Anonynn
31 Oct 2017, 06:09Yeah, something wonky is happening. I probably need Pixie @_@ Nothing is getting set for some reason.

K.V.
31 Oct 2017, 06:17Happy to help!
Take your time.
Resolve those errors.
Your problems are not insurmountable.
Shop smart. Shop S-Mart!
Make Quest kneel before you!!!
WE'LL SWALLOW YOUR SOUL!!!
(Sorry... I'm watching Evil Dead while trying to ignore a 'How to be a Successful Businessperson' CD, which I can't help but hear as it blares from an adjacent room. (I've gone a little crazy crazier, too, it seems.))

Anonynn
31 Oct 2017, 06:18LOL Love that movie. I KICKASS FOR THE LORD! xD ! I haven't seen it in forever. And yeah, I know the problems aren't insurmountable, but I need this Creator to be working by the 3rd, so I'm freaking out now! Hahah! I've been working really hard on it for the past week or two.
Anonynn.

K.V.
31 Oct 2017, 06:21Wasn't there some reason to not use game.pov in your game one time, Anonynn?
It seems like you had to use player one time...
Was that you?
Am I dreaming up stuff?
Or is that what made you ask:
Isn't it player.pov?
Hrmm...
Try:
heights = Split("5.0;5.2;5.4;5.6;5.8;6.0;6.2", ";")
if (player.gender="female") {
player.height = heights[GetRandomInt(0,5)]
}
else {
player.height = heights[GetRandomInt(1,6)]
}
msg ("You are "+player.height+" units tall.")

K.V.
31 Oct 2017, 06:25I KICKASS FOR THE LORD! xD
Hey!!!
I just watched that before Evil Dead!
That's Dead Alive (or Braindead) by Peter Jackson, and it's freaking SWEET!
I think I was messing you up with the game.pov
instead of player
.
If that doesn't fix it, I'm willing to check out the code, if you'd like.

Anonynn
31 Oct 2017, 06:29I believe I have to use player.pov---I'll try switching the scripts. I believe I fixed all the other errors happening except that height one now. ^_^ I'll let you know in a moment.
I can't tell you how many "Out of Memory" errors I get with the size of these scripts xD I think I have 21 to 42 if-scripts in some of them, which by the way is the absolute max that Quest can handle before crashing.
Anonynn.

K.V.
31 Oct 2017, 06:37If player.pov.height
doesn't work, try player.height
.
I can't tell you how many "Out of Memory" errors I get...
Word up?
(Note to self: I'm not pushing Quest hard enough.)

K.V.
31 Oct 2017, 08:23I just whippped this up for anyone who wishes to have a little fun while learning about lists:
http://textadventures.co.uk/games/view/jxfbggsn7kizjf4brkkodq/fun-with-lists
I'll be adding the random stuff tomorrow, along with a few odds and ends I left out (like different ways to manipulate the lists).
mrangel
31 Oct 2017, 11:10I believe I have to use player.pov
No. player
is the default name of the player object; game.pov
is the attribute Quest uses internally to keep track of which object is the player. If you allow the player to control different characters, game.pov
will always be the current player.
game.pov
and player
are equivalent (unless you change the name of the player object); there is no player.pov unless you created it.
The only reason not to use game.pov
all the time is because there's a couple of places that don't like too many dots; like in the text parser.

K.V.
31 Oct 2017, 11:45Is there a Quest function that will round a double integer up to the nearest hundredth?
Like converting 3.86666666666667
to 3.87
?
I'm using JS and an ASLEvent in this little example I made, but Anonynn would prefer avoiding the JS, if possible, I'm sure.
JS
roundUp = function(dbl){
dbl = Math.round(100*dbl)/100;
addText("<br/>dbl: "+dbl+"<br/>");
ASLEvent("setRoundedHeight", dbl);
}
<beforefirstenter type="script">
player.health_as_int = 3.86666666666667
x = player.health_as_int
msg (x)
JS.roundUp (x)
</beforefirstenter>
<function name="setRoundedHeight" parameters="height">
player.height = height
msg ("player.height: "+player.height)
player.height_as_int = ToDouble(height)
msg ("player.height_as_int: "+player.height_as_int)
</function>
Output:
3.86666666666667
dbl: 3.87
You are in a room.
player.height: 3.87
player.height_as_int: 3.87
Anonynn has all sorts of scripts tying to her height_as_int
attribute.
This example uses the height I was assigned during a play-through.

K.V.
31 Oct 2017, 12:32Duh!
Never mind that last question.
EDIT: I put health
when it should have been height
.
player.height = 3.86666666666667
x = player.height_as_int
msg (x)
if (LengthOf(ToString(x))>4) {
x = round(100*x)/100
msg ("Rounded: "+x)
}
mrangel
31 Oct 2017, 14:00player.health_as_int = 3.86666666666667
I think that's a double, not an int.
Also, if it's for display, you could use
msg ("Rounded: "+Left(ToString(x), 4))
If I was using rounded versions a lot, I'd probably use a script something like:
player.changedhealth_as_double => {
healths = Split(ToString(this.health_as_double)+".00", ".")
this.health_as_string = healths[0] + "." + Left (healths[1]+"00", 2)
this.health_to_2dp = round (this.health_as_double*100)/100
this.health_as_int = ToInt(healths[0])
}

K.V.
31 Oct 2017, 14:04I think that's a double, not an int.
Exactly, and it's messing some scripts up.
I think it was and integer in the beginning, but that's just a wild theory.
This is what throws out the long doubles (and incorrect figures; i.e., when player.height is 6.0, this puts out 4'11"):
height_in_inches = player.height_as_int * 2 + 36
height_in_cm = 254 * height_in_inches / 100
s = (height_in_inches / 12) + "' " + (height_in_inches % 12) + "\" (" + (height_in_cm / 100.0) + " m)"

K.V.
31 Oct 2017, 20:38Okay, I think I fixed it (and I'm hoping it doesn't negatively effect some other script somewhere):
height_in_inches = player.height_as_int * 12
feet = height_in_inches/12
inches = height_in_inches % 12
a = floor(feet)*30.48
b = floor(inches)*2.54
s = floor(feet) + "' " + floor(inches) + "\" (" + round(a+b)/100 + " m)"
mrangel (and any other mathematically inclined forum members who may be interested, bored, or what have you),
Do you see any discrepancies (or shortcuts I could have taken)?
(player.height
looks like it can range from 3.0 to 7.0.)
It appears to work out correctly each time with a random value.

Anonynn
31 Oct 2017, 21:43Hello! Sorry I've been in class all day @_@
Yes, the heights range from 3.0 to 7.0 and go by two's, for example, 3.0, 3.2, 3.4 etc.
As for the //height_as_int// I believe a majority of the time I use that as a text processor command.
For instance...
{if player.height_as_int>=5: Anything over the 4th Stringlist number will enable the script.}
At least, that's how it's used for other attributes in the game, like weight and so on.
I appreciate everyone weighing in on this so far! ^_^
Anonynn.
hegemonkhan
01 Nov 2017, 03:41(filler for getting edited post, updated/posted)
game.height_minimum_double_attribute = 3.0
game.height_maximum_double_attribute = 7.0
game.height_increment_double_attribute = 0.2
// ------------------------------------------------
height_double_variable = game.height_minimum_double_attribute
// initial: height_double_variable = 3.0
// this is our 'counter' VARIABLE for the 'while', and also it's the (full range/amount of) height values being added to our height list
upper_out_of_bounds_double_variable = game.height_maximum_double_attribute + game.height_increment_double_attribute
// upper_out_of_bounds_double_variable = 7.0 + 0.2 = 7.2
//
// this is just so I can remove the equals operation from the while, so instead of doing '<= (less than or equal to)', I am just doing '< (less than)', thus greatly reducing the number of operations
//
// (the larger the list, the greater the number of operations being reduced), for example (reducing operations by half):
//
// 10 (items in list) / 2 (pretend modifier of operations being removed) = 5 operations removed
// vs
// 1,000,000,000 (items in a list) / 2 (pretend modifier of operations being removed) = 500,000,000 operations removed
//
// big difference when you're removing 500 million operations
// small difference when you're removing only 5 operations
//
// the '/ 2' (pretend modifier of operations being reduced) represents: 2 operations (lesser than and equal to) / 2 (removing the 'equals' operation out) = 1 operation (lesser than) FOR EACH ITEM IN THE LIST, instead of doing 2 operations FOR EACH ITEM IN THE LIST. The number of operations (2) are being reduced by half, thus doing only 1 (2 / 2 = 1) operation PER EACH ITEM IN THE LIST
height_stringlist_variable = NewStringList ()
while (height_double_variable < upper_out_of_bounds_double_variable) {
list add (height_stringlist_variable, height_double_variable)
height_double_variable = height_double_variable + game.height_increment_double_attribute
}
list_count_integer_variable = ListCount (height_stringlist_variable)
last_index_number_integer_variable = list_count_integer_variable - 1
random_index_number_integer_variable = GetRandomInt (0, last_index_number_integer_variable)
random_height_string_variable = StringListItem (height_stringlist_variable, random_index_number_integer_variable)
player.height_double_attribute = ToDouble (random_height_string_variable)