Thread: Save/load keyvalues between levels

Results 1 to 14 of 14
  1. #1
    func_vehicle enthusiaist w00tguy123's Avatar
    Join Date
    Dec 2006
    Location
    U.S. West
    Posts
    1,599

    Save/load keyvalues between levels

    Attached are two example maps that transfer a value (999) from one map to another. The save sequence uses 66 ents to save a number (the "renderamt" keyvalue in the "wallet" entity) with a range of 0-1024. An additional 4 ents can be added to support a value up to 2048, and then another 4 for 4096, and so on. The save sequence is not instantaneous - it took about 5 seconds to convert my value of 999. The load sequence is much simpler, made up of 20 ents in my case. Loading is instantaneous.

    The first map converts the keyvalue to a binary number (displayed using buttons) which is saved using env_globals. The second map converts the binary sequence back into a decimal number as soon as the map loads.

    To plug this into your own maps, copy and paste the clusters of entities in the binary_save map and add a copy_value that copies your keyvalue to the "renderamt" key in the "wallet" entity. For the binary_load map, copy and paste the trigger_autos and trigger_changevalues. Then, either copy and paste the "wallet" entity, or change the targets and keyvalues of the trigger_changevalues to the entity and keyvalue you want.
    Attached Files Attached Files
    Last edited by w00tguy123; 08-01-2012 at 10:31 PM.
    Love,
    w00tguy

  2. #2
    Registered User
    Join Date
    Apr 2003
    Location
    Missouri, US
    Posts
    6,344

    Re: Save/load keyvalues between levels

    Oh sweet, I didn't actually think someone would do this.

    The next thing you can attempt to do is implement binary compression algorithms. X-D

  3. #3
    QPU-aligned Silencer's Avatar  
    Contributor
    Join Date
    May 2006
    Posts
    6,082

    Re: Save/load keyvalues between levels

    Well done, but just silly if you need to transfer many values. It should be possible to do both, save/load, instantaneous.

  4. #4
    func_vehicle enthusiaist w00tguy123's Avatar
    Join Date
    Dec 2006
    Location
    U.S. West
    Posts
    1,599

    Re: Save/load keyvalues between levels

    @Silencer: Thanks! The slowdown comes from decreasing the value until it reaches zero. That is the only way I could think of to check if the value has a remainder. The alternative, and much faster way, would have been to compare two keyvalues (the value and an int version of that value), but that's not possible with 4.5 ents. Even if that were possible, the amount of entities involved in saving would still cause some delay (maybe more like 1 sec for the value 999) because I can't trigger each step at the same time.

    @Qwerty: Yea, that was a good idea for a workaround to the trigger_save/load issue. Before, the only way I thought this could be done was by trying to represent the decimal value with buttons.... that would have been messy! Now I can haz my rupees and savez dem too.
    Love,
    w00tguy

  5. #5
    Still learning wolf-3d's Avatar  
    Tester
    Join Date
    Jan 2011
    Location
    Somewhere Warm.
    Posts
    1,474

    Thumbs up Re: Save/load keyvalues between levels

    Hi w00tguy123,

    Just fell across this while forum browsing, Good Work , I especially liked a few "tricks" you used:
    rendermode/int, trigger_changevalue/trigger_changetarget, multi_manager/while looping.

    But a question:
    In binary_save.rmf you DID NOT go all the way and put in multi_sources for any of the env_globals, I thought the engine wouldn't cope (leading to unexpected behaviour) but it seem to be stable, is this because the "global state" is otherwise not referenced in map1 and not required in map2 due to the use of trigger_auto's ?

    Can you (or anyone else) confirm this is acceptable/stable within the SC engine?

    regards
    Wolf-3D

    EDIT PS: "The slowdown comes from decreasing the value until it reaches zero" ? I am guessing you are a bit hard on yourself, the func_train and buttons won't be required in the majority of cases, which would drop entity count by about 12 and increase the speed quite a bit.
    Last edited by wolf-3d; 06-12-2011 at 10:04 AM.

  6. #6
    func_vehicle enthusiaist w00tguy123's Avatar
    Join Date
    Dec 2006
    Location
    U.S. West
    Posts
    1,599

    Re: Save/load keyvalues between levels

    This system is obsolete as of 4.6. I'm not sure if we can actually save and load keyvalues between maps now but this system can be made much faster using the new features in copyvalue/changevalue/etc.

    Edit: Just looked at the new trigger_save/load features and they still don't work between maps... I'll work on a better version of this now.

    @wolf: this system might not be as stable as it could be because I use timers to schedule everything. If the server has epic lag or something then it might mess up the save. In the new version I'll use the new "trigger after operation" keyvalue so that something like this never happens.
    Last edited by w00tguy123; 08-01-2012 at 08:26 PM.
    Love,
    w00tguy

  7. #7
    func_vehicle enthusiaist w00tguy123's Avatar
    Join Date
    Dec 2006
    Location
    U.S. West
    Posts
    1,599

    Re: Save/load keyvalues between levels

    Alright, I just finished the second version (dl at first post). Saving a keyvalue is now instantaneous.

    I added two more links in the chain to support saving up a value up to 4096 (in case you want to save position coordinates). You can remove links if you don't need to save something that big, or add more.
    Love,
    w00tguy

  8. #8
    QPU-aligned Silencer's Avatar  
    Contributor
    Join Date
    May 2006
    Posts
    6,082

    Re: Save/load keyvalues between levels

    I think I will adjust trigger_save/load to be able to access any map's save file. Will also need to increase its efficiency because right now there is HDD access every time you load/save.

  9. #9
    Still learning wolf-3d's Avatar  
    Tester
    Join Date
    Jan 2011
    Location
    Somewhere Warm.
    Posts
    1,474

    Re: Save/load keyvalues between levels

    Quote Originally Posted by w00tguy123 View Post
    Alright, I just finished the second version (dl at first post). Saving a keyvalue is now instantaneous.
    Aargh Wootguy beat me to it , my 4.5 way for transfering data also sort of gliched, so I am/was merging bits of my old method (array of 2^power + game_counter) with your div/2 method and ... it doesn't work the last time I checked. Pity as some of the tricks you used are very good. [FFS - just read my old post here and realised I didn't use one of your tricks. The Multitreaded Multi_Manager. ] I will have one last look at what I was doing for interest and if it doesn't work, scrap it. [ and download your new version.]

    Quote Originally Posted by Silencer View Post
    I think I will adjust trigger_save/load to be able to access any map's save file. Will also need to increase its efficiency because right now there is HDD access every time you load/save.
    Good News for the Long term, or does this mean are we getting 4.7 really soon ? :biggrin:

    regards
    Wolf-3D

  10. #10
    Still learning wolf-3d's Avatar  
    Tester
    Join Date
    Jan 2011
    Location
    Somewhere Warm.
    Posts
    1,474

    Re: Save/load keyvalues between levels

    Here is my 4.6 Offering of transfering data between two maps. Which is largely based on Wootguy's original example. It takes the "Kills" from _amap1 to _amap2.

    Instructions Compile both maps, find & load _amap1.bsp. Press a button, wait for all zombies to spawn (or if you chose 1023, go when bored) then change to _amap2 (use door/arch/passage/thingy).

    The Max. No. that can be transfered across maps with this version is 1023. (1024-1)
    The "Core" logic entities used are on the wall behind the cross hairs in given pic. (start at bottom entity & work up) the rest is same layout as Wootguy.
    NB: There may be a few unused entities about as I could not fix the array version which attempted to take another 3x (max No. 1023) across to _amap2. (Duplicate the existing env_globals etc. bump me or Wootguy or someone, if you cannot do this.)

    You can do what you want with the source but this is Wootguy's Thread so if you use any of it Credit:
    w00tguy123 and provide a link to this Thread.

    regards
    Wolf-3D

    EDIT:
    Forgot to check for missing textures/non standard textures, add numbers.wad file to wad compile list if necessary:
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	eg_map12.jpg 
Views:	73 
Size:	540.6 KB 
ID:	14817  
    Attached Files Attached Files
    Last edited by wolf-3d; 10-01-2012 at 10:54 AM.

  11. #11
    QPU-aligned Silencer's Avatar  
    Contributor
    Join Date
    May 2006
    Posts
    6,082

    Re: Save/load keyvalues between levels

    About trigger_save security issues: How about trigger_save can only access save files of maps which ran after last time global data was cleared or a mapchange initiated by game_end occured? I.e.:

    map1.bsp runs and clears previous levels.
    trigger_changelevel to map2.bsp.
    trigger_changelevel to map3.bsp.
    trigger_changelevel to othermap1.bsp and clears previous levels.
    trigger_changelevel to othermap2.bsp.
    map change to map_selection_lobby.bsp by game_end; does not clear previous levels.

    map1.bsp can access map1.save.
    map2.bsp can access map1.save and map2.save.
    map3.bsp can access map1.save, map2.save and map3.save.
    othermap1.bsp can access othermap1.save.
    othermap2.bsp can access othermap1.save and othermap2.save.
    map_selection_lobby.bsp can access only map_selection_lobby.save, despite not clearing previous levels, because it got loaded as a result of game_end, not as a result of a trigger_changelevel.

    Good enough?

  12. #12
    Still learning wolf-3d's Avatar  
    Tester
    Join Date
    Jan 2011
    Location
    Somewhere Warm.
    Posts
    1,474

    Re: Save/load keyvalues between levels

    Quote Originally Posted by Silencer View Post
    About trigger_save security issues: How about trigger_save can only access save files of maps which ran after last time global data was cleared or a mapchange initiated by game_end occured? I.e.:

    ...
    ...

    Good enough?
    Seems to cover all the scenarios I can think of. But I still think Trigger_Save can be "left as is" in SC4.6, we just have to give Trigger_load access to Pre-existing map.save's or as above.

    regards
    Wolf-3D

    EDIT: Just checked in-case I was missing something but as I thought Trigger_Save overwrites the current_map_name.save which is really all I would need from the trigger_save entity (Ability to create + Modify in it's own map name).
    Then it is up to individual mappers to remember the names of their prior maps in any map series, and load or not load.
    Last edited by wolf-3d; 10-01-2012 at 04:53 PM.

  13. #13
    QPU-aligned Silencer's Avatar  
    Contributor
    Join Date
    May 2006
    Posts
    6,082

    Re: Save/load keyvalues between levels

    In theory, yes. However as soon as you want maps to have shared data and won't be able to save them centralized it's going to be annoying.

  14. #14
    Still learning wolf-3d's Avatar  
    Tester
    Join Date
    Jan 2011
    Location
    Somewhere Warm.
    Posts
    1,474

    Re: Save/load keyvalues between levels

    Quote Originally Posted by Silencer View Post
    In theory, yes. However as soon as you want maps to have shared data and won't be able to save them centralized it's going to be annoying.
    I thought all "map.save" files were created\saved in the ......\half-life\SvenCoop\maps directory.

    I also thought that if you create multipule tigger_saves in any map, the additonal trigger_saves result in a new line, in the form:

    label : string

    e.g. a test.save file of mine:
    mapfilename_msg:Greetings from Map1
    mapfilename_gc:16
    mapfilename_med:1
    mapfilename_torch:0

    (This is a security issue in that the *.save file can be continually written to, during a 60 min game, also if you are allowed to write to other map_name.save besides your own map_name, then you just need to store a 129chr$ continual string and it will freeze most servers, when a Trigger_Load tries to open the data later on.)

    And yes it would be nice to get at each individual line of data but we have string functions now in 4.6 so we can concatonate to:
    mapfilename_data:0 1 16 Greetings from Map1
    Load to to game_text:message or $s_data and substring/parse out.

    It is also possible I don't have a clue what you are trying to say/get across

    regards
    Wolf-3D

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •