English map conversion .s2s script (fixed)

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 1×, last 21.09.21 03:41:20 am
I stopped modding because it didn't explain quantum mechanics
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 stopped modding because it didn't explain quantum mechanics
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 stopped modding because it didn't explain quantum mechanics
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.

p.s. strangely enough, after I finished the script I got bored and made no further modifications to the script, so I haven't really used it for anything since I made the script. This will obviously change in the future once I get past my temporary lack of motivation.

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.
edited 3×, last 22.09.21 06:21:39 am
I stopped modding because it didn't explain quantum mechanics
To the start Previous 1 Next To the start