Page 1 of 1

Moding help

PostPosted: 09 Mar 2012, 18:59
by eliminator
I have made a series of world maps all connecting to each other. But when someone gets to the 3rd world or higher it doesn't save his position. The maps stay won but when you exit supertux and go back on supertux you are on then 2nd world and you have to travel all the way through worlds 3 4 and 5 to get to world 6. How can I make it save you position?

Also in maps what script do I use to make you spawn at another sector/spawning point?

I am using the newest SVN version.

Re: Moding help

PostPosted: 09 Mar 2012, 20:35
by ctdabomb
hmmmm......
can I see the levels and worldmaps? or are they super-secret plans for Nolok's domination of the world?

Re: Moding help

PostPosted: 09 Mar 2012, 23:48
by eliminator
I could post the level. Has anyone made a series of world maps that exceed 3? If so how did they make your position save?

Re: Moding help

PostPosted: 10 Mar 2012, 00:52
by ctdabomb
you can try looking a LMH's maps, they have 2.... it might help some.

Re: Moding help

PostPosted: 10 Mar 2012, 01:49
by eliminator
No, It wont because the normal game also has 2... I already looked at it.

Re: Moding help

PostPosted: 10 Mar 2012, 02:51
by ctdabomb
Then I guess I will have to see the levels if you don't mind, so I can try to help.

Re: Moding help

PostPosted: 10 Mar 2012, 02:56
by ctdabomb
or as a cheap fix, you could just also have all your levels on one worldmap and just teleport to a different spot.

Re: Moding help

PostPosted: 10 Mar 2012, 21:40
by LMH
Support of multiple worldmaps is not something that is currently inherent in the game. I'm actually a bit surprised to hear that two are working. Ideally, someone would sit down and put the necessary coding together to make multiple worlds work easily, but until that happens you'll probably need to brute force it using scripting and state variables. The best thing would be to put together some squirrel code in a .nut file, but if you don't know how to make that work (or don't want to) you can also probably make it work in the worldmap initialization script. Because I use a sort of "non-traditional" file hierarchy in my own levels, this is what I had to do to make it work in my own levels (it didn't automatically even for two maps for me). I'm only using two worldmaps at the moment but intend to have at least three, so the trick I developed should work well enough for you (I haven't tried yet myself and can't for a few weeks so this is a bit of an assumption).

Anyway I'm sure you're ultimately interested in the necessary code, so I'll try to cover it as best I can. First you will need to establish some state variable(s) to denote which worldmap you want loaded when the player returns. State variables are saved after exiting and contain information such as level stats (located in your profile folder). I've been using a boolean (true/false) for each worlmap to denote which is active, but that's probably not the most efficient for a large number of worlmaps. You could experiment with a single integer or string in a case structure if you wish, but until I can play around with better ways I'll stick with what I already know works. Start with something like:

{l Code}: {l Select All Code}
if(! ("map1" in state)){state.map1<- true;}
if(! ("map2" in state)){state.map2<- false;}
if(! ("map3" in state)){state.map3<- false;}


Using my method, you need to have a line for every worldmap you are using- this initializes the state variable if it does not yet exist (note at first only map1 should be true). Next you will need a little code to handle the change to go to the correct worldmap. I've been using something like this:

{l Code}: {l Select All Code}
if(!state.map1){ exit_screen();
  if(state.map2){ load_worldmap(\"levels/<world name>/world2/worldmap.stwm\");}
  if(state.map3){ load_worldmap(\"levels/<world name>/world3/worldmap.stwm\");}
} else {<any normal map initialization code if used>}


The code up to this point should only need to be on the first worldmap and executed during initialization (maybe the second, with some tweaks, if it actually loads automatically already). Anyway what it does is first checks to see if you are on the right map, if not it closes it (otherwise it runs the optional code in the else statement). Then it looks to find which map you are suppose to be on and loads it instead. You will obviously have to use the correct path to your worldmaps and include lines for all your worlds. SuperTux automatically remembers the coordinates where you left off, so you do not have to worry about spawnpoints or anything like that.

Finally, you are going to need to set up some way to set the state variables in-game so that it all actually works. I use a special tile that is immediately after a spawnpoint of a map to set the correct variable, for example in world 3 you would use the script:

{l Code}: {l Select All Code}
state.map3<- true;
state.map2<- false;


I do not worry about map1 because I have no way to get from world 1 to world 3 (thus it should already be set correctly); however, any map that links to world 3 should also be set to false in this script as well (for example world 4 would be a logical choice to also include assuming you can go backward).

That should be enough to get it to work. I realize this is not the best or most efficient way to do this, but it should work and is conceptually pretty simple. If you want more elaboration, just let me know. I'd put together a demo, but I don't have access to SuperTux for a couple of weeks.

Hope that helps.

Re: Moding help

PostPosted: 08 May 2022, 18:26
by Z-man
Cool scripts, LMH! I want to copy and paste them for a NUT file for a world-map I'll make some day. :D