System The Shortest Save/Load Code Ever

Reaction score
341
I Like your codes length and all. But it bugs once i gather 6 items in your demo map.

It loads either no items or a bunch of different items. How can you not be getting this bug, I change nothing in the code.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
It uses "call SetRandomSeed(seed)" in several places... with a fixed value.
This would also be the only save / load code doing so.

Well, I'm sure there's a valid reason... :p

Poor cleeeeez though was working out a "bug" in his map for about a week.
As such, the description should probably mention this.
Or make sure it can't happen.
 

Korolen

New User (Why do I keep getting those red bars?)
Reaction score
69
It uses "call SetRandomSeed(seed)" in several places... with a fixed value.
This would also be the only save / load code doing so.

Well, I'm sure there's a valid reason... :p

Poor cleeeeez though was working out a "bug" in his map for about a week.
As such, the description should probably mention this.
Or make sure it can't happen.

Kode seeds the random generator based on a player's name, and then uses the "random" results to start changing the code around to encrypt it. To decrypt, it calculates the same seed based on the player's name and thus the "random" numbers it gets when decrypting turn out to be the same ones it got when encrypting. I thought it was pretty ingenious...

Anyway, it does nothing to reset the random number generator afterwords, so it pretty much hijacks any randomness you happened to be doing at the time.

If I had time I'd release an update to Kode with lots of improvements, but right now, I don't really feel the temptation – I haven't opened the World Editor for more than a few minutes at a time in many, many months.

At this point, Kode gets the job done. It makes codes. I leave it up to its users to integrate it into their maps. Kode is a technology; my original intent in publishing it was just to share what I had just spent days making. Anyone expecting something other than that will be disappointed.

By the way, the issue with saving six items: the item_count variable should have a maximum value of 7, not 6, as 0 means "no items." Just change the sixes to sevens and it'll work fine. (Acehart, please refrain from harping on me about how if there wasn't a fixed maximum value for saving numbers, then there wouldn't be that bug. It was seriously easy to find, especially when you make Kode complain when you try to save a number beyond its maximum.)

EDIT: Just to clarify, what I mean is change push_int(item_count, 6) to push_int(item_count, 7) and set item_count = pop_int(6) to set item_count = pop_int(7). This is all done in the JASS save and load triggers for Demo 3.
 
Reaction score
341
I am obviously doing something wrong. I Tried saving and loading but the values just got all messed up.... :rolleyes:

JASS:
library Kode initializer InitTrig uses KodeBase

private function Item2Int takes integer t returns integer
    local integer i = 0
    loop
        exitwhen i >= MAX_ITEMS
        if udg_Items<i> == t then
            return i
        endif
        set i = i + 1
    endloop
    return -1
endfunction

function Save takes player p returns nothing
    local integer i = GetPlayerId(p)
    local integer l = 0
    call clear_bits()
    call push_int(GetHeroLevel(Hero<i>), 50)
    loop
        exitwhen l &gt; 5
        call push_int(Item2Int(GetItemTypeId(UnitItemInSlot(Hero<i>, i))), MAX_ITEMS)
        set l = l + 1
    endloop
    call push_int(GetHeroStr(Hero<i>, false), 300)
    call push_int(GetHeroInt(Hero<i>, false), 300)
    call push_int(GetHeroAgi(Hero<i>, false), 300)
    call push_int(Toughness<i>, 300)
    call push_int(Initiative<i>, 300)
    call push_int(Willpower<i>, 300)
    call push_int(Luck<i>, 300)
    call DisplayTextToPlayer(p, 0, 0, format_code(create_code(p, 10), 4))
endfunction

private function LoadHero takes nothing returns nothing
    local integer id = GetPlayerId(GetTriggerPlayer())
    local integer i  = 0
    local integer l  = 0
    set Hero[id]     = CreateUnit(GetTriggerPlayer(), &#039;HERO&#039;, -10569, 9786, 0)
    
    call SetHeroLevel(Hero[id],  pop_int(50), false) 
    loop
        exitwhen i &gt; 5
        set l = pop_int(MAX_ITEMS)
        call UnitAddItemById(Hero[id], udg_Items[l])
        set i = i + 1
    endloop
    call SetHeroStr(Hero<i>, pop_int(300), false)
    call SetHeroAgi(Hero<i>, pop_int(300), false)
    call SetHeroInt(Hero<i>, pop_int(300), false)
    set Toughness<i> = pop_int(300)
    set Initiative<i> = pop_int(300)
    set Willpower<i> = pop_int(300)
    set Luck<i> = pop_int(300)
endfunction

private function Load takes nothing returns nothing
    call LoadHero()
endfunction
//===========================================================================
private function InitTrig takes nothing returns nothing
    local trigger t2 = CreateTrigger()
    local integer i = 0
    loop
        exitwhen i &gt; 11
        call TriggerRegisterPlayerChatEvent(t2, Player(i), &quot;-load&quot;, false)
        set i = i + 1
    endloop
    call TriggerAddAction(t2, function Load)
endfunction

endlibrary

</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>
 

Korolen

New User (Why do I keep getting those red bars?)
Reaction score
69
I am obviously doing something wrong. I Tried saving and loading but the values just got all messed up.... :rolleyes:

JASS:
library Kode initializer InitTrig uses KodeBase

private function Item2Int takes integer t returns integer
    local integer i = 0
    loop
        exitwhen i &gt;= MAX_ITEMS
        if udg_Items<i> == t then
            return i
        endif
        set i = i + 1
    endloop
    return -1
endfunction

function Save takes player p returns nothing
    local integer i = GetPlayerId(p)
    local integer l = 0
    call clear_bits()
    call push_int(GetHeroLevel(Hero<i>), 50)
    loop
        exitwhen l &gt; 5
        call push_int(Item2Int(GetItemTypeId(UnitItemInSlot(Hero<i>, i))), MAX_ITEMS)
        set l = l + 1
    endloop
    call push_int(GetHeroStr(Hero<i>, false), 300)
    call push_int(GetHeroInt(Hero<i>, false), 300)
    call push_int(GetHeroAgi(Hero<i>, false), 300)
    call push_int(Toughness<i>, 300)
    call push_int(Initiative<i>, 300)
    call push_int(Willpower<i>, 300)
    call push_int(Luck<i>, 300)
    call DisplayTextToPlayer(p, 0, 0, format_code(create_code(p, 10), 4))
endfunction

private function LoadHero takes nothing returns nothing
    local integer id = GetPlayerId(GetTriggerPlayer())
    local integer i  = 0
    local integer l  = 0
    set Hero[id]     = CreateUnit(GetTriggerPlayer(), &#039;HERO&#039;, -10569, 9786, 0)
    
    call SetHeroLevel(Hero[id],  pop_int(50), false) 
    loop
        exitwhen i &gt; 5
        set l = pop_int(MAX_ITEMS)
        call UnitAddItemById(Hero[id], udg_Items[l])
        set i = i + 1
    endloop
    call SetHeroStr(Hero<i>, pop_int(300), false)
    call SetHeroAgi(Hero<i>, pop_int(300), false)
    call SetHeroInt(Hero<i>, pop_int(300), false)
    set Toughness<i> = pop_int(300)
    set Initiative<i> = pop_int(300)
    set Willpower<i> = pop_int(300)
    set Luck<i> = pop_int(300)
endfunction

private function Load takes nothing returns nothing
    call LoadHero()
endfunction
//===========================================================================
private function InitTrig takes nothing returns nothing
    local trigger t2 = CreateTrigger()
    local integer i = 0
    loop
        exitwhen i &gt; 11
        call TriggerRegisterPlayerChatEvent(t2, Player(i), &quot;-load&quot;, false)
        set i = i + 1
    endloop
    call TriggerAddAction(t2, function Load)
endfunction

endlibrary

</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>


Not to be rude, but your problem is pretty basic. The Kode guide should help you out.

Korolen said:
You MUST retrieve the numbers in reverse order they were put onto the code, and the maximum values must match exactly what they in the saving. For example, if you store a hero level, then the player's gold and lumber, you would pop off the lumber, then the gold, and then the hero level.
 

Rocker742

New Member
Reaction score
0
uhm I know this may sound stupid, but what do you mean by execute? like go to the trigger? I'm probably overthinking but it got me confused
 

Korolen

New User (Why do I keep getting those red bars?)
Reaction score
69
uhm I know this may sound stupid, but what do you mean by execute? like go to the trigger? I'm probably overthinking but it got me confused

Code:
Trigger - Run (Ignoring Conditions)

Look at the code in the demos for examples.
 

No_exit

Regular User (What is Custom User Title?)
Reaction score
40
Ok I managed to read through Kode's code and get a good idea of how the system works.

The system is indeed extremely efficient and probably the shortest load code made so far in average (sorry had to put it in bold, I don't want AceHart's anger over me :p) but I don't fully agree with the following quote:

It wastes *zero* space when saving normal integers because they have an arbitrary maximum size.

This might be true in theory, but in practice this will not be the case.
A lot of maps (especially big RPGs) release their map which they know is not their final version. This means that the creators generally have no idea for example how many items their final map will have. This will lead to one of the following two scenarios:
- You say to the save code that the max amount of items you can have is the max of the current map. This means that if you add more items in your next version of your map, the previous codes will no longer work or in other words: the players will have to start a new hero which is very painful imo.
- You overestimate the max amount of items (generally by some safe amount to make sure that no code reset ever happens) which will make you lose some space.
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
Whats with this GetRandomInt Problem? I don't really understood this.

I want to use Kode, but I'm not sure how it will affect my map, since I use a lot of random Ints ...

Can someone explain to me what this Seed thingy means and how it works?
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
Let's take the following list: 2, 4, 5, 1, 3.

Imagine that's the entire and complete list of all possible random numbers.
The random number generator will give you those, in the mentioned order.

Now, when the map starts, he will decide on where he's going to start in the list.
First time you play, it might be the given order.
Next time, it might be 5, 1, 3, 2, 4.
Still the same numbers, but you start somewhere else.
That somewhere else is the seed.

And, when you get the same seed as previously, the numbers will come in exactly the same order as previously.


Well, strange as it may seem, that's how random numbers work.
Fortunately, the list has about 4 billions(*) of them... :p

Still, with the seed being the same, you get the same numbers every time...


JASS:
set SomeInteger = GetRandomInt(0, 1000000) // get a number while it still works
... do whatever
call SetRandomSeed(SomeInteger) // use it to still get random numbers after





(*) on a 32bit generator. With any luck, they're using a 64bit generator.
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
So basicly most of the time (unless you use a ridicolous amount of random Ints) you don't have to bother about it?
 

R 3 T R O

New Member
Reaction score
12
Is this MPI? Becaouse the Demo_Damage, Demo_Kills and Demo_Mana are just an integra they are not even an array and the trigger only has an event for player red.
 

Korolen

New User (Why do I keep getting those red bars?)
Reaction score
69
Is this MPI? Becaouse the Demo_Damage, Demo_Kills and Demo_Mana are just an integra they are not even an array and the trigger only has an event for player red.

While that particular demo is not MPI, rest assured that the Kode internals can easily generate numerous codes for each player, one right after the other if the need be.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top