English map conversion script further progress

6 replies
Goto Page
To the start Previous 1 Next To the start
Up
ModJuicer
Super User
Offline Off
So I created two scripts to convert maps across from mods. The first script saves all the values of all the objects, and the second one loads all the objects using those values.

The first script works, but I can't get the second one to. I'm trying to get it to call the variables using a string (which is stored inside a variable) because I can't think of any other way.

First script (which already works):
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
on:load{
     loop("objects"){
          $object=loop_id();
          $topid=$object;
          $yaw=getyaw ("object",$object);
          $pitch=getpitch ("object",$object);
          $roll=getroll ("object",$object);
          $x=getx("object",$object);
          $y=gety("object",$object);
          $z=getz("object",$object);
          $type=type("object",$object);
          $varstring="objectyaw$object";
          rename "yaw","$varstring";
          $varstring="objectpitch$object";
          rename "pitch","$varstring";
          $varstring="objectroll$object";
          rename "roll","$varstring";
          $varstring="objectx$object";
          rename "x","$varstring";
          $varstring="objecty$object";
          rename "y","$varstring";
          $varstring="objectz$object";
          rename "z","$varstring";
          $varstring="objecttype$object";
          rename "type","$varstring";
          $varstring="objectid$object";
          rename "object","$varstring";
     }
     savevars "maps/vars";
}


Second script (which doesn't work):

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
on:start{
     loadvars "maps/vars";
     $object=1;
     loop("count",99999){
          if($object>=$topid){
               exit;
          }
          $varstring="objectid$object";
          if(varexists("$varstring")){
               $varstring="objectyaw$object";
               $objectyaw=$varstring;
               $varstring="objectroll$object";
               $objectroll=$varstring;
               $varstring="objectpitch$object";
               $objectpitch=$varstring;
               $varstring="objectx$object";
               $objectx=$varstring;
               $varstring="objecty$object";
               $objecty=$varstring;
               $varstring="objectz$object";
               $objectz=$varstring;
               $varstring="objecttype$object";
               $objecttype=$varstring;
               $varstring="objectid$object";
               $objectid=$varstring;
               create "object",$objecttype;
               debug "vars";
               //setrot "object",$newobject, $objectpitch, $objectyaw, $objectroll;
               //setpos "object",$newobject,$objectx,$objecty,$objectz;
          }
          $object++;
     }
}



My current problem has been: The more complex the codes get, the less people there are that know how to help me, so to simplify:

is it possible in s2 script to take this variable:
          $varstring="objectpitch$object";
and use the string stored inside to call a different variable with the same name as the string stored inside?
edited 3×, last 07.06.22 02:56:46 am
I've been making extensive progress on Stranded II Enhanced lately. I am hoping to release a new update soon. Spoiler: There will be fully functional tanks, planes can be enabled to drop bombs, and much more. Stay tuned for the release.
20.09.21 10:29:09 pm
Up
Hurri04
Super User
Offline Off
what the bloody hell are you even doing with that "varstring" variable and the rename command all the time?

you already have the values you want to save, just concatenate them normally into a string.

and check out this again:
https://www.unrealsoftware.de/forum_posts.php?post=424047&start=0#post424083
21.09.21 12:25:29 am
Up
ModJuicer
Super User
Offline Off
I completely forgot about that (I blame bad attention span for that). Thank you so much! That makes things much easier. I must have not been good enough at scripting back then. I'll do it and edit in the result script after, so anyone can use it.
I've been making extensive progress on Stranded II Enhanced lately. I am hoping to release a new update soon. Spoiler: There will be fully functional tanks, planes can be enabled to drop bombs, and much more. Stay tuned for the release.
21.09.21 12:57:05 am
Up
Hurri04
Super User
Offline Off
user ModJuicer has written:
and edit in the result script after

no, for the love of god, stop editing your comments so much. at the end of the day noone even knows what was originally written anymore, and in what order.

just make a normal post and everyone who wants to read it can scroll down and follow the conversation.
21.09.21 03:32:34 am
Up
ModJuicer
Super User
Offline Off
makes sense. Anyway, I (kind of) figured it out after about two hours of debugging. It skips over the last object, but I'm sick of debugging for now (maybe i'll fix it later). (an easy fix is just to add an extra object before running)

One thing that will prove quite useful about these scripts: they can stack on already-existing maps, and there aren't id-collision problems (if object with id 1 is saved on the first one, it might not be object 1 on the second map. if object 1 already exists it will make it object 2 etc.)

Anyway, the result of over 6 hours of scripting and debugging (because of hyper-focusing) right here:

Object Saving Code >


Object Loading Code >



There are some other quirks in the code as well: I left in the 'echo' commands for debugging, It doesn't save scripts (which are easy enough to import manually). Also, if you noticed, it adds 1000 to the rotation variables, and 10000 to the coordinate variables in the saving script, and subtracts that amount in the loading script. That was done as a workaround because negative numbers ruined the code. Anyway, anyone can feel free to use or improve upon this code, which was definitely not worth the time it took to make.


EDIT:
Quote:
no, for the love of god, stop editing your comments so much. at the end of the day noone even knows what was originally written anymore, and in what order.

just make a normal post and everyone who wants to read it can scroll down and follow the conversation.


Thanks for the constructive criticism. I don't get much of it, so I feel the need to recognize when I do get it. Respect

EDIT2:

Also, this script can be used for objects, units, items, etc. (ctrl-H replace 'object' with 'unit' or 'item') . It won't save or load any manually added features (like scripts, change of health/maxhealth, states, or stored items), because there's no point in writing a complex script (which would take a few more hours) for something that can be manually added easily into the game.
edited 1×, last 21.09.21 03:50:38 am
I've been making extensive progress on Stranded II Enhanced lately. I am hoping to release a new update soon. Spoiler: There will be fully functional tanks, planes can be enabled to drop bombs, and much more. Stay tuned for the release.
21.09.21 06:09:40 pm
Up
Hurri04
Super User
Offline Off
that's one way of doing it.

the way I described it groups all values for a single object, then puts the next block for next object and so on.

and typically you concatenate new elements to the end of a list, not the other way around.

this would allow joining all variables with a single command, like
Code:
1
list = join list, separator, type, separator, x, separator, y, separator, z, separator, ...

one thing in your implementation, which I didnt think of, is just using multiple variables for the different classes, that way your dont need the "^" in my other post.

if you increment a variable "objectCount"/"unitCount"/etc. after each object and save that as well, you can know the number of iterations for the loop when deserializing.

savevars also has the option to only save specific variables btw.

and if you create a variable "object;unit;item;info" and split it 4 times in a first loops which sets a "class" variable, then call a custom "on:serialize" event you can serialize all classes in one go, without needing to edit the script in between. this is a bit of a hacky workaround to S2 not supporting custom methods with parameters. the same for deserializing ofc.
22.09.21 05:38:35 am
Up
ModJuicer
Super User
Offline Off
Yeah. The main reason I like the method I used is because it would be easy to convert over (ex. in one mod tree id is 3, while in the other one it's 32, I can automatically run another script that converts the tree from 3 to 32, so I get the correct model, instead of a random model (or no model at all, which leads to the game crashing) . It could also be used to convert any model that doesn't exist into a dummy object, preventing a game crash as well as marking where objects are that don't exist in the version/mod.

This script will be the base upon which all my future map converters are coded. Because I can save colormap, heightmap, and scripts, this will make a great multi-purpose code for converting maps.

Quote:
typically you concatenate new elements to the end of a list, not the other way around


I tried that, but s2s is weird, so it counts the strings in reverse for some reason. Really strange, but at least I figured it out and got it to work.

EDIT: I'm interested in improving Cast Away, but the versions available seem limited. The only versions that seem to exist are 0.0.0.1d (german) and 0.0.0.2 (english). Unfortunately for me (because I speak english) it seems the english version bricked a few features. Maybe I could fix some stuff, if there was a bit more comment code.

EDIT2: The script I made beforehand had a few bugs, which I have ironed out.

New (working) code:

--Object saving code--
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
on:load{
     $objectids="";
     $objecttypes="";
     $objectyaws="";
     $objectrolls="";
     $objectpitchs="";
     $objectzs="";
     $objectxs="";
     $objectys="";
     $loopcountup=0;
     loop("objects"){

          $object=loop_id();
          $objectids=join("$object",";","$objectids");

          $yaw=getyaw ("object",$object);
          $yaw+=1000;
          $objectyaws=join("$yaw",";","$objectyaws");

          $pitch=getpitch ("object",$object);
          $pitch+=1000;
          $objectpitchs=join("$pitch",";","$objectpitchs");
          
          $roll=getroll ("object",$object);
          $roll+=1000;
          $objectrolls=join("$roll",";","$objectrolls");

          $x=getx("object",$object);
          $x+=10000;
          $objectxs=join("$x",";","$objectxs");
          
          $y=gety("object",$object);
          $y+=10000;
          $objectys=join("$y",";","$objectys");
          
          $z=getz("object",$object);
          $z+=10000;
          $objectzs=join("$z",";","$objectzs");
          
          $type=type("object",$object);
          $objecttypes=join("$type",";","$objecttypes");
          $loopcountup++;
     }
     savevars "maps/vars";
}


--Object loading code--
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
on:load{
     loadvars "maps/vars";
     $object=0;
     loop("count",$loopcountup){
          $objectid=split("$objectids",";",$object);
          $objectyaw=split("$objectyaws",";",$object);
          $objectyaw-=1000;
          echo "objectyaw $objectyaw";
          $objectroll=split("$objectrolls",";",$object);
          $objectroll-=1000;
          echo "objectroll $objectroll";
          $objectpitch=split("$objectpitchs",";",$object);
          $objectpitch-=1000;
          echo "objectpitch $objectpitch";
          $objectx=split("$objectxs",";",$object);
          $objectx-=10000;
          echo "objectx $objectx";
          $objecty=split("$objectys",";",$object);
          $objecty-=10000;
          echo "objecty $objecty";
          $objectz=split("$objectzs",";",$object);
          $objectz-=10000;
          echo "objectz $objectz";
          $objecttype=split("$objecttypes",";",$object);
          echo "objecttype $objecttype";
          $objectid=split("$objectids",";",$object);
          echo "objectid $objectid";
          $newobject=create("object",$objecttype);
          echo "newobject $newobject";
          setrot "object",$newobject, $objectpitch, $objectyaw, $objectroll;
          setpos "object",$newobject,$objectx,$objecty,$objectz;
          $object+=1;
     }
}


Sorry It's taken so long (almost a year) for me to fix the script. I got distracted by real life. A few side notes:

• The other script had two bugs, one regarding ids (1 id too high) and one regarding loops.

• I may make it automatically segment the script into smaller chunks or multiple files in the future (possibly with different functions) in order to reduce lag and/or increase usability.

• I will probably use one or more custom file extensions (ones that won't be confused with preexisting Stranded II file types) in order to make the script more manageable.

• I may, in the future, create a code that executes relative to an entity (for example an info). This would make it possible to save and load smaller collections of objects at a relative position. In addition, the ability to filter out objects that aren't in a specified range would make it much easier to save smaller collections of objects at a time.

• In the context of smaller collections of objects (ex. structures, villages, multi-piece houses, etc.) it may be quite useful upon saving to save the terrain upon which they stand and upon loading to load the same local terrain gradient where it is created, as this would lead to less discontinuities between the terrain and the positions of the objects.

• It will be useful, in the future, to have a loading script that can detect invalid ids before the object is created (when a script attempts to create invalid objects it leads to an error) and either change the id to the equivalent object from the different stranded II mod/version, change it to a specified dummy object, or skip its placement and echo a message on the console detailing info on the skipped object (id, type, etc).

• Cross swapping mod map scripts, designed to port maps specifically from one mod to the other as complete as is possible, would help, especially in the context of updating versions, which sometimes have slight id changes, as well as importing maps from other mods.

• I may or may not include saving terrain in the script. It may actually be easier to just save a heightmap separately. However, for local placements it may be more manageable.
edited 6×, last 07.06.22 02:54:08 am
I've been making extensive progress on Stranded II Enhanced lately. I am hoping to release a new update soon. Spoiler: There will be fully functional tanks, planes can be enabled to drop bombs, and much more. Stay tuned for the release.
To the start Previous 1 Next To the start