Randomized Maps

Hello there. im not looking for scripts i would like to do this all in common events and such if possible.


im trying to get my maps to arrange them selves in a random order.


example: i have a starting map and 9 other maps. the player walks to the east edge of the start map and is transferred to any one of the other 9 maps, but when the player walks to the east edge of the next map they are transferred to one of the remaining 8 maps. so on and so forth. 


so each play through you would traverse the maps in a different and random order (like a rogue-like) 


HOWEVER the player needs to be able to traverse back through the maps but no longer in a random order.


so say on one playthrough the maps are layed out as such: start, 3, 5, 2, 7, 9, 8, 4, 6 and the player is currently on map 6. then they walk to the west edge they are transferred back to map 4


so basically i am generating a world made of smaller maps and once the world is generated it is saved and does not change so the player can freely move about it


i know this can be done with scripting and arrays and it would probably make life a whole lot easier, and i understand the sudo code but i dont know or understand the language and trying to frustrate my self over learning it and want to avoid loosing my steam on making this project (which is why i would like common events to keep it as simple as possible)


things i know i need:


a way to create random numbers within a range and no repeats


a way to assign maps random numbers to be called upon later


a way to assign a transfer event to the map previously on


thanks for any help in advance
Ok I am on my phone and at work.  So I will give you a simple way.  If you need more help on it, let me know in the forums.


So if your 9 maps are 3x3.  You will need to create 9 variables.  Pretend the variables are a grid.   When you randomize them.  They will need ed to be placed in order.   Map 5 in variable 1.  Variable 1 would be coordinates 0,0.  


The transfer player will need to be always transfered to those coords which saves the map info.  


Then for the random numbers you will need to do variable = script.  Script will be math.rand or something.  You will need to google that.  There are several ways to store, loop, or xheck if a map was alrwady picked....sorry got a customer...
yeah ive had some time to fuss with it. what ive come up with is a grid of variables


a1 a2 a3  


b1 b2 b3


c1 c2 c3          


in a common event i have a random number being assigned to each in order starting from a1. using nested conditional branches i have it check each for which numbers were used and not to repeat


however this gets cumbersome with nested conditional branches and very confusing to keep track of.


ex: generate a1 (no checks required);


loop,


generate rnd#,


if rnd# = a1 end,


else assign rnd# to a2


end loop;


new loop,


generate rnd#,


if rnd# = a1 end,


else (nested otherwise doesnt check right) if rnd# = a2 end,


else assign rnd# to a3...etc


until c3 which now has 8 nested conditional branches which just looks a mess.


it gets the job done but my project will have a very large amount of maps. at the moment im only using 9 maps as a proof of concept to get the core of it all made.


another issue is with player transfers between maps. in order to transfer players with a variable, the x, y of the new position also needs to be variables. so every map needs to be the same size to cut down on just the sheer amount of variables ide need since each different sized map would need atleast 2 new variables rather than 2 variables that work universally across all maps (in actuality i need a total of 8 variables to hold x, y positions for map transfers since the maps can be entered from all 4 sides) i can make due with this though, but if you have a way around that ide love to hear it so my maps can be more diverse. 


so really all i need is a better way to create random numbers and no repeats with out super nested conditional branches


in total im looking to have like 100 different maps, (ambitious i know lol) so by the 100th grid cell being generated having 99 conditional branches nested inside can be a real pain to keep strait
Im at work for 6 more hours.  But....just make a seperate common event to run a quick check on your random number.  That way you can just run a call each time.  


Also are the exits the entire side of the maps or specific spots? 


Label start


Rand# b1


Call common event check number


If trigger = on then jump to start


So not to make this too complicated.  You could imbed all that into a loop also that incrementally increases the variable # so you dont need 9 segments of code.


So 


Loop


Rand# check


If ok


Increase var#


Im trying to do this quick while working.
------------------So I don't double post------------


----Common Event 1------


Variable99 = 0


Loop


Variable99 = Variable99+1 


Call Common Event(2)


if variable99 = 9 break loop


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


-----Common Event 2---------


switch(whatever) = off


Loop


$gameVariables.value($gameVariables.value(99)) = Math.randomInt(8)+1    "This is the only real code in all of this."


Call Common Event 3


if switch(whatever) = off


Break loop


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


-----Common Event 3------------


variable100 = 0


Loop


variable100 = variable100+1


if $gameVariables.value($gameVariables.value(99) == $gameVariables.value($gameVariables.value(100) && $gameVariables.value(99) != $gameVariables.value(100)


switch(whatever) = on


if variables100 = 9


break loop


That is all you need to do to get the 9 random maps.


So what I did was create 3 loops. 


The First loop is going to rotate through 9 variables.


The Second loop is going generate random numbers for the 9 variables.


The Third loop is going to check the current map variables you are on with the others.  If it equals the map data of another map and DOES NOT equal the variable id number then a switch will turn off.  If it turns on then that means it found a duplicate and is going to generate a new one.


If this is too much for you let me know and I can just write out all the script for you.  I am in sales in real life and Friday/Saturday/Sunday I work long hours and also working on my game at the moment.  So I am writing this super quickly before I head off to work.  I figured that I have not paid my community dues yet for all the people who have helped me.


*The $gameVariables stuff needs to be put into the script on MV.
thanks for the help. the problem with me and code is more of, its never explained enough for me to truly understand. so if i paste it into the game and some where down the line i need to fix or change something, it screws up a lot since i dont have a full understanding. if you could help explain some of this into further detail, but no rush, you dont have to sneak posts in at work. im currently snowed in so i dont have work today lol


----Common Event 1------


Variable99 = 0   \\ setting up a variable, got it (-o-o)b. why call it variable99? i know it could be called anything 


Loop


Variable99 = Variable99+1  


Call Common Event(2)


if variable99 = 9 break loop 


\\ so my understanding of this is: create a loop, call common event(2) 9 times


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


-----Common Event 2---------


switch(whatever) = off \\create switch, call it what i want, got it


Loop


$gameVariables.value($gameVariables.value(99)) = Math.randomInt(8)+1    "This is the only real code in all of this."


\\|................^...............|.....................^...................|.................^..................|


\\|........question 1........|.............question 2.............|..........rnd# 1 to 9.........|


\\q1. this script call gets the value of "($gameVariables.value(99))"?


\\q2. ($gameVariables.value(99)) is being set to a random number? why "(99)"?


Call Common Event 3


if switch(whatever) = off


Break loop


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


-----Common Event 3------------


variable100 = 0 \\new var, again why variable100? what is the significance of the number in the variable name?


Loop


variable100 = variable100+1 \\ again creating steps of a ladder through adding 1 each loop


if $gameVariables.value($gameVariables.value(99) == $gameVariables.value($gameVariables.value(100) && $gameVariables.value(99) != $gameVariables.value(100)


\\ if the value of this ----------------^ is equal to the value of this --------------------------^ and the value of this ------------------^ "!=" what is this opperand?


switch(whatever) = on


if variables100 = 9 \\repeat loop 9 times then end loop


break loop


so all this is to generate 9 random numbers with out repeats, how can i hook this into assigning those random numbers to my grid?
-------Common Event 1--------


variable99 I was just using as a suggestion like using slot 99 on your variable list.  I wasn't sure what you had open.  I didn't explain that at all lol.  


But variable99 is used as a counter for the 9 variables.  So variable99 is just used for referencing which variable we are looking at.


So if I have variable(1), variable(2), variable(3).  It is actually just variable(n).  n = variable99.  The whole reason for this is to prevent you from having to do this 9 times.  


If n = 5.  Then we are now doing variable(5).  This is where  $gameVariables.value($gameVariables.value(99)) comes into play.


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


So if you get a chance, checkout the script call list on the forums. http://forums.rpgmakerweb.com/index.php?/topic/46456-rpg-maker-mv-script-call-list/  It is stickied at the top.  Someone made a list.  This list is script code that you can use in the RPGMV scripting.


So before I go too deep, I will go over some of the scripting you can do in RpgMaker.


$gameVariables.setValue(var, value);


$gameVariables.setValue(1,10);  Instead of assigning a variable through the RpgMaker script thingy, you can tab over to the end and click script.  Type that in and you now just set variable slot 1 to value 10.


Now back to the counter.  The one I called variable99.


Lets from this point on call it CounterVariable1.  It will still be in slot 99 on your variable list.  Variables 1-9 are used for map coordinates.  Variables 99 and 100 will be counters.


Variable 101 will be for the random number.  So we need 12 total variables for this.


$gameVariables.setValue($gameVariables.value(99), RandomNumber))


So the statement above is setting the value of N to a random number.  Where N is a counter used to cycle through which variables we want to assign.  The statement above will be looped 9 times.  Each time $gameVariables.value(99) will need to = 1,2,3,4,5,6,7,8,9.  We will 9 times set the value to 9 different variables.  


Btw, I enjoy showing you how this works more than actually just giving you the script.  I am sort of rushing through.  But for now I will end this.  I first want to make sure you understand how to script in MV.  Before I go any further I want to make sure you can manually set a variable through pure scripting.


$gameVariables.value(1); "This is calling the value of variable 1"


$gameVariables.setValue(1,10); "This is setting the value of variable 1 to 10.  


if ($gameVariables.value(1) == 10){


$gameSwitches.setValue(1, true);}


This snippet of code will set switch 1 to ON if you set variable 1 to 10.  Do not forget semicolons when hard scripting in MV.


* btw != means does not equal to.


Let me know how you fair and we will move onto the next part.  Anything you don't understand let me know.  I have Mondays off and Tuesdays off, so I can create a more organized and clear post for you.  I am typing this all up in 15 minutes before I go to bed.

Original thread: https://forums.rpgmakerweb.com/threads/randomized-maps.55436/