So, I'm working on creating a randomly generated map in Sugarcube 2 for my game. It's slow, but I'll get there. I've run into my first issue however. What I'm trying to do is place a loop withing an array, and that loop contains a set function that will select a random number from a predetermined list. Here, the code will explain itself, or well better I I can at least.
[
<<for $i = 0; $i < 10; $i++>>
<<set $i to either (0, 0, 0, 1)
<</for>>
]
If someone could tell me where I went wrong or what I need to do would be great. Thank you in advance.
Comments
I'm pretty sure you need to add a >> to close off the set macro and (possibly) remove the space between either and its args (...)
Also, you "can't" use $i in both places unless you want an infinite loop because $i will never be greater than 10 if you set it to either(0, 0, 0, 1) on every pass. You'll want to use different variable names for your index and for your map's... wall assignment?
You may have been looking for something like the following: That will populate $listOfNumbers with ten randomly chosen numbers, whose values will be either 1 (3/4 chance) or 0 (1/4 chance).
Based on your example, I'm assuming that is the result you were attempting to achieve.
Also JackWinters, my map has no walls, as I am just trying to get a basic map down, I'll get borders and slow uncovering of the map eventually.
1. Both of your for loops are doing the same number of iterations so you can combine them into one.
2. Your first either() function is randomly choosing between two zero's so it is not needed.
Try the following:
Also, the shown code is less than optimal—greyelf has already pointed that out and offered suggestions to improve it, so that's all I'll say about it.