For Loop Problem!

onimike
07 Oct 2017, 13:08

So in my loop i clone and move objects to players room, all seems to work fine but the top 3 loops. The bottom 6 loops work as intended giving me random number of said objects while the top 3 for grass, plantfiber and tree only give one. Now the only difference is in the "In steps of "Expression" " i had to put the variable name or number of steps where as the others i can leave blank. If i try to leave others blank I get an error where as others do not have a problem and spawn up fine in random numbers. Here's code so you can see what im saying

gras = GetRandomInt(1,5)
tre = GetRandomInt(1,4)
plan = GetRandomInt(1,2)
stic = GetRandomInt(1,3)
ston = GetRandomInt(1,2)
brom = GetRandomInt(1,3)
mush = GetRandomInt(1,2)
bamb = GetRandomInt(1,3)
boul = GetRandomInt(1,2)
if (RandomChance(75)) {
  for (a, 1, gras, gras) { *This is what im talking about I need this here or error
    CloneObjectAndMove (grass, player.parent)
  }
  for (c, 1, tre, tre) {
    CloneObjectAndMove (tree, player.parent)
  }
  for (f, 1, plan, plan) {
    CloneObjectAndMove (plantfiber, player.parent)
  }
}
if (RandomChance(50)) {
  for (d, 1, stic) { *And need nothing here and works fine???
    CloneObjectAndMove (sticks, player.parent)
  }
  for (e, 1, ston) {
    CloneObjectAndMove (stone, player.parent)
  }
  for (i, 1, brom) {
    CloneObjectAndMove (bromelian, player.parent)
  }
}
if (RandomChance(40)) {
  for (b, 1, mush) {
    CloneObjectAndMove (mushroom, player.parent)
  }
  for (g, 1, bamb) {
    CloneObjectAndMove (bamboo tree, player.parent)
  }
  for (h, 1, boul) {
    CloneObjectAndMove (boulder, player.parent)
  }
}

Any help is appreciated thanks!

Mike


hegemonkhan
07 Oct 2017, 13:42

do you need the step/interval Parameter?

1 to 5, interval/step 5:

1: runs script
1+5 = 6 (out of range of the 1 to 5) = no run script and for loop done

all of them (a, c, f) are only able to run once, when you got the step/interval being the same as your max value

(having no interval/step Parameter/Value, means the default of '1' is used: 1 to 5 = 1, 2, 3, 4, 5 = 5 loops/runs)

(or if the default value no longer works, you can do this, manually inputing the use of a '1' step/interval: for (a, 1, gras, 1)

gras = GetRandomInt(1,5)
tre = GetRandomInt(1,4)
plan = GetRandomInt(1,2)
stic = GetRandomInt(1,3)
ston = GetRandomInt(1,2)
brom = GetRandomInt(1,3)
mush = GetRandomInt(1,2)
bamb = GetRandomInt(1,3)
boul = GetRandomInt(1,2)
if (RandomChance(75)) {
  for (a, 1, gras) { *This is what im talking about I need this here or error
    CloneObjectAndMove (grass, player.parent)
  }
  for (c, 1, tre) {
    CloneObjectAndMove (tree, player.parent)
  }
  for (f, 1, plan) {
    CloneObjectAndMove (plantfiber, player.parent)
  }
}
if (RandomChance(50)) {
  for (d, 1, stic) { *And need nothing here and works fine???
    CloneObjectAndMove (sticks, player.parent)
  }
  for (e, 1, ston) {
    CloneObjectAndMove (stone, player.parent)
  }
  for (i, 1, brom) {
    CloneObjectAndMove (bromelian, player.parent)
  }
}
if (RandomChance(40)) {
  for (b, 1, mush) {
    CloneObjectAndMove (mushroom, player.parent)
  }
  for (g, 1, bamb) {
    CloneObjectAndMove (bamboo tree, player.parent)
  }
  for (h, 1, boul) {
    CloneObjectAndMove (boulder, player.parent)
  }
}

hegemonkhan
07 Oct 2017, 14:00

(filler for getting my edited post, updated/posted)


if you do want to use a randomization for the step value, you'd have to do this, an example:

for (example, 1, GetRandomInt (1, 100), GetRandomInt (1, 100)) { /* scripting */ }

examples:

1 to 100, step 100 = 1, 1 + 100 (101 = out of range of 1 to 100) = 1 run script only
1 to 100, step 1 = 1, 2, 3, ... , 100 = 100 run scripts
1 to 100, step 50 = 1, 51, 101 (out of range of 1 to 100) = 2 run scripts only
1 to 100, step 25 = 1, 26, 51, 76, 101 (out of range of 1 to 100) = 4 run scripts only
1 to 100, step 10 = 1, 11, 21, 31, 41, 51, 61, 71, 81, 91, 101 (out of range of 1 to 100) = 10 run scripts only

1 to 50, step 50 = 1, 51 (out of range of 1 to 50) = 1 run script only
1 to 50, step 25 = 1, 26, 51 (out of range of 1 to 50) = 2 run scripts only
etc etc etc

1 to 75, step 75= 1, 76 (out of range of 1 to 75) = 1 run script only
etc etc etc

etc etc etc

---------------------

the reason is that:

VARIABLE = GetRandomInt (MIN, MAX)

means that the 'GetRandomInt' is only done once for this run, the 'VARIABLE' has a set-single (randomly selected) Value, which is being used for your MAX and STEP/INTERVAL Value:

VARIABLE = GetRandomInt (1, 100)

VARIABLE = 71
for (a, VARIABLE, VARIABLE)
// for (a, 1, 71, 71)

VARIABLE = 39
for (a, VARIABLE, VARIABLE)
// for (a, 1, 39, 39)

whereas:

for (a, GetRandomInt (1, 100), GetRandomInt (1, 100))
examples:
// for (a, 100, 1)
// for (a, 1, 100)
// for (a, 75, 25)
// for (a, 25, 75)
// for (a, 81, 4)
etc etc etc

hegemonkhan
07 Oct 2017, 14:15

actually, you might want this:

msg ("Select Max Value for Randomization")
get input {
  if (IsInt (result) and ToInt (result) > 0 and ToInt (result) < 501) { // I just randomly chose '500' for the max loops
    max_randomization_integer_variable = result
  } else {
    msg ("wrong input, try again")
    // recall the scripting again (if you want them to be stuck, until they enter the right input)
  }
}
for (a, 1, GetRandomInt (1, max_randomization_integer_variable), GetRandomInt (1, max_randomization_integer_variable)) {
  // blah scripting
}

onimike
07 Oct 2017, 14:22

Thanks HK I was able to fix by doing this

gras = GetRandomInt(1,5)
tre = GetRandomInt(1,4)
plan = GetRandomInt(1,2)
stic = GetRandomInt(1,3)
ston = GetRandomInt(1,2)
brom = GetRandomInt(1,3)
mush = GetRandomInt(1,2)
bamb = GetRandomInt(1,3)
boul = GetRandomInt(1,2)
if (RandomChance(75)) {
  for (a, 1, 5, gras) {
    CloneObjectAndMove (grass, player.parent)
  }
  for (c, 1, 4, tre) {
    CloneObjectAndMove (tree, player.parent)
  }
  for (f, 1, 2, plan) {
    CloneObjectAndMove (plantfiber, player.parent)
  }
}
if (RandomChance(50)) {
  for (d, 1, 3, stic) {
    CloneObjectAndMove (sticks, player.parent)
  }
  for (e, 1, 2, ston) {
    CloneObjectAndMove (stone, player.parent)
  }
  for (i, 1, 3, bro) {
    CloneObjectAndMove (bromelian, player.parent)
  }
}
if (RandomChance(40)) {
  for (b, 1, 2, mush) {
    CloneObjectAndMove (mushroom, player.parent)
  }
  for (g, 1, 3, bamb) {
    CloneObjectAndMove (bamboo tree, player.parent)
  }
  for (h, 1, 2, boul) {
    CloneObjectAndMove (boulder, player.parent)
  }
}

Works great now..

Thanks again
Mike


mrangel
07 Oct 2017, 15:04

Hmm… interesting probabilities there. So if there's grass, trees, and plantfiber in a room, you have 1,2,3, or 5 grass (with 2 being twice as likely as the other numbers), 1,2, or 4 trees (2 more likely again), and 1 or 2 fibers.

I've never seen that way of doing it before, but looks like it'll be an interesting distribution.