• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Loading wrong value

Status
Not open for further replies.
Level 12
Joined
Nov 3, 2013
Messages
989
The "Great Fire" for player 1 is being misplaced. It's not appearing at 0, 0 either though. (And there's no region which has the same x and y at their center as where it appears)

  • buildSys init
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Custom script: set udg_hash_buildSys = InitHashtable()
      • -------- units for handle id --------
      • Set buildSys_unit[0] = |c00FF0000Hall of Warchief|r 0025 <gen>
      • Set buildSys_unit[1] = |c00FF0000Hall of Warchief|r 0026 <gen>
      • Set buildSys_unit[2] = |c00FF0000Hall of Warchief|r 0027 <gen>
      • -------- ability raw codes --------
      • Set buildSys_abilityId[0] = Build Dummy (Barracks)
      • Set buildSys_abilityId[1] = Build Dummy (Stronghold Towers)
      • Set buildSys_abilityId[2] = Build Dummy (Great Fire)
      • -------- dummy ability raw codes --------
      • Set buildSys_abilityIdDisabled[0] = Build Dummy Disabled (Barracks)
      • Set buildSys_abilityIdDisabled[1] = Build Dummy Disabled (Stronghold Towers)
      • Set buildSys_abilityIdDisabled[2] = Build Dummy Disabled (Great Fire)
      • -------- Player 1 barracks --------
      • Set buildSys_integer[0] = 0
      • Set buildSys_uType[0] = |c00FF0000Barracks|r (Bloodbane)
      • Set buildSys_real[0] = 3726.00
      • Set buildSys_real[1] = -6572.00
      • Set buildSys_real[2] = 358.00
      • -------- Player 1 stronghold towers --------
      • Set buildSys_integer[1] = 3
      • Set buildSys_uType[1] = |c00FF0000Stronghold Tower|r
      • Set buildSys_real[3] = (X of (Center of Tower Red 1 <gen>))
      • Set buildSys_real[4] = (Y of (Center of Tower Red 1 <gen>))
      • Set buildSys_real[5] = 270.00
      • Set buildSys_real[6] = (X of (Center of Tower Red 2 <gen>))
      • Set buildSys_real[7] = (Y of (Center of Tower Red 2 <gen>))
      • Set buildSys_real[8] = 270.00
      • Set buildSys_real[9] = (X of (Center of Tower Red 3 <gen>))
      • Set buildSys_real[10] = (Y of (Center of Tower Red 3 <gen>))
      • Set buildSys_real[11] = 270.00
      • Set buildSys_real[12] = (X of (Center of Tower Red 4 <gen>))
      • Set buildSys_real[13] = (Y of (Center of Tower Red 4 <gen>))
      • Set buildSys_real[14] = 270.00
      • -------- Player 1 Great Fire --------
      • Set buildSys_integer[2] = 0
      • Set buildSys_uType[2] = |c00FF0000Great Fire|r
      • Set buildSys_real[15] = (X of (Center of Bonfire Red <gen>))
      • Set buildSys_real[16] = (Y of (Center of Bonfire Red <gen>))
      • Set buildSys_real[17] = 270.00
      • -------- run the trigger which will store all the values in the hashtable --------
      • Trigger - Run buildSys store loops Copy 2 <gen> (ignoring conditions)
JASS:
function Trig_buildSys_store_loops_Copy_2_Actions takes nothing returns nothing
    local integer i = 0
    local integer j
    local integer a = 0
    local integer b
    local integer h
    local integer aId
    local integer n
    loop
        exitwhen udg_buildSys_abilityId[a] == 0
        call SaveInteger(udg_hash_buildSys, udg_buildSys_abilityId[a], 0, udg_buildSys_abilityIdDisabled[a])
        set a = a +1
    endloop
    call DisplayTextToForce( GetPlayersAll(), "a = " + (I2S(a) ) )
    loop
        set h = GetHandleId( udg_buildSys_unit[i] )
        exitwhen h == 0
        call DisplayTextToForce( GetPlayersAll(), "i = " + (I2S(i) ) )
        set j = 0
        loop
            set aId =  udg_buildSys_abilityId[j]
            exitwhen aId == 0
            call DisplayTextToForce( GetPlayersAll(),  "j = " + ( I2S(j) ) )
            set n = i * a + j
            call SaveInteger(udg_hash_buildSys, h, aId, n)
            call SaveInteger(udg_hash_buildSys, n, 0, udg_buildSys_integer[n])
            call SaveInteger(udg_hash_buildSys, n, 1, udg_buildSys_uType[n])
            set b = 0
            loop
                exitwhen udg_buildSys_real[b] == 0
                call DisplayTextToForce( GetPlayersAll(),  "b = " + ( I2S(b) ) )
                call SaveReal(udg_hash_buildSys, n, 2 + b, udg_buildSys_real[b])
                set b = b +1
            endloop
            set j = j +1
        endloop
        set i = i +1
    endloop
endfunction

//===========================================================================
function InitTrig_buildSys_store_loops_Copy_2 takes nothing returns nothing
    set gg_trg_buildSys_store_loops_Copy_2 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_buildSys_store_loops_Copy_2, function Trig_buildSys_store_loops_Copy_2_Actions )
endfunction
JASS:
function Trig_buildSys_start_Func004C takes nothing returns boolean
    if ( ( GetSpellAbilityId() == 'A02B' ) ) then
        return true
    endif
    if ( ( GetSpellAbilityId() == 'A02C' ) ) then
        return true
    endif
    if ( ( GetSpellAbilityId() == 'A06Z' ) ) then
        return true
    endif
    if ( ( GetSpellAbilityId() == 'A05V' ) ) then
        return true
    endif
    if ( ( GetSpellAbilityId() == 'A074' ) ) then
        return true
    endif
    if ( ( GetSpellAbilityId() == 'A072' ) ) then
        return true
    endif
    return false
endfunction

function Trig_buildSys_start_Conditions takes nothing returns boolean
    if ( not Trig_buildSys_start_Func004C() ) then
        return false
    endif
    return true
endfunction

function Trig_buildSys_start_Actions takes nothing returns nothing
    local integer i = 0
    local integer j
    local integer a = GetSpellAbilityId()
    local integer n
    local integer uNum
    local integer uType
    local real array uXYF
    set udg_u = GetTriggerUnit()
    set udg_p = GetTriggerPlayer()
    set udg_i = GetConvertedPlayerId(udg_p)
    set n = LoadInteger( udg_hash_buildSys, GetHandleId( udg_u ), a )
    call UnitRemoveAbility( udg_u, a )
    call UnitAddAbility( udg_u,  LoadInteger( udg_hash_buildSys, a, 0 ) )
    // number of buildings to be built
    set uNum = LoadInteger( udg_hash_buildSys, n, 0 )
    // unit type of building(s) to be built
    set uType = LoadInteger( udg_hash_buildSys, n, 1 )
    loop
        // i loops = number of buildings to be built
        exitwhen i > uNum
        set j = 0
        loop
            // j loops = x, y and facing angle for each building
            exitwhen j > 2
            set uXYF[j] = LoadReal( udg_hash_buildSys, n, i * 3 + 2 + j )
            set j = j +1
        endloop
        call CreateUnit( udg_p, uType, uXYF[0], uXYF[1], uXYF[2] )
        set i = i + 1
    endloop
endfunction

//===========================================================================
function InitTrig_buildSys_start takes nothing returns nothing
    set gg_trg_buildSys_start = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_buildSys_start, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_buildSys_start, Condition( function Trig_buildSys_start_Conditions ) )
    call TriggerAddAction( gg_trg_buildSys_start, function Trig_buildSys_start_Actions )
endfunction

PS. there's no need to mention the location leaks
 
Last edited:

Zwiebelchen

Hosted Project GR
Level 35
Joined
Sep 17, 2009
Messages
7,236
From what I see, you are trying to manage a 2-dimensional array out of a 1-dimensional integer by using this formula: n = i * a + j
So far, so good.


After iterating through the first loop with integer a, a holds the value 3 (if we take your GUI trigger as a base). This is basicly your new max index.

So in the first iteration of the i-loop and j-loop, you basicly have this:
n = 0*3+0 = 0
In the second iteration of the j-loop, you have this:
n = 0*3+1 = 1
In the third iteration, you have this:
n = 0*3+2 = 2

Now, i increments by 1; so you have this:
In first iteration of j-loop, you have this:
n = 1*3+0 = 3
In the second iteration of the j-loop, you have this:
n = 1*3+1 = 4
In the third iteration, you have this:
n = 1*3+2 = 5

You now get the real stored in the real array at index n+b. n is 0 at the first iteration, so this becomes:
Real[0+0] to Real[0+17].
And that's exactly what you want from what I see.


But here comes the problem: in the next iteration of the j loop n is now 1, reading the values of Real[n+b]. As n = 1, you now read Real[1..17] instead of Real[0..17] like you did before.


Phew, this was actually a very lengthy explanation for a simple issue. Change Real[n+b] to Real and it should work.

PS: I haven't checked the load trigger yet. This was just what I noticed in the save trigger. It might be possible that load has bugs too.
 
Level 12
Joined
Nov 3, 2013
Messages
989
From what I see, you are trying to manage a 2-dimensional array out of a 1-dimensional integer by using this formula: n = i * a + j
So far, so good.
So that I can use it in an actual 2d array as a 3d one with: unit, ability raw code, number.

After iterating through the first loop with integer a, a holds the value 3 (if we take your GUI trigger as a base). This is basicly your new max index.
Sorry what? variable a in the store trigger isn't related to the other loops, it's just for saving dummy abilities to the real abilities. Later in the load when you use the ability it's removed and the dummy ability is added instead, it doesn't really have anything to do with the other loops :c[/quote]


So in the first iteration of the i-loop and j-loop, you basicly have this:
n = 0*3+0 = 0
In the second iteration of the j-loop, you have this:
n = 0*3+1 = 1
In the third iteration, you have this:
n = 0*3+2 = 2

Now, i increments by 1; so you have this:
In first iteration of j-loop, you have this:
n = 1*3+0 = 3
In the second iteration of the j-loop, you have this:
n = 1*3+1 = 4
In the third iteration, you have this:
n = 1*3+2 = 5

You now get the real stored in the real array at index n+b. n is 0 at the first iteration, so this becomes:
Real[0+0] to Real[0+17].
And that's exactly what you want from what I see.
yeah, thing is I had to store the integers too (and ability ID has it's own variable in GUI so two variables for it) but I wouldn't want to put them in the same index order as the reals since they're using different variables.

But here comes the problem: in the next iteration of the j loop n is now 1, reading the values of Real[n+b]. As n = 1, you now read Real[1..17] instead of Real[0..17] like you did before.

Phew, this was actually a very lengthy explanation for a simple issue. Change Real[n+b] to Real and it should work.


Thanks, I were looking mostly in the load trigger because it were spooking me out a bit with the loads while I were tinkering with it. For some reason I barely even considered the actual source and look I had dome some weird stuff and forgot to make a variable for carrying over the total index.

call SaveReal(udg_hash_buildSys, n, 2 + b, udg_buildSys_real[banana * 3 + b])

set banana = banana + udg_buildSys_integer[n] + 1

JASS:
function Trig_buildSys_store_loops_Copy_2_Actions takes nothing returns nothing
    local integer i = 0
    local integer j
    local integer a = 0
    local integer b
    local integer bNum
    local integer bNumTotal = 0
    local integer h
    local integer aId
    local integer n
    loop
        exitwhen udg_buildSys_abilityId[a] == 0
        call SaveInteger(udg_hash_buildSys, udg_buildSys_abilityId[a], 0, udg_buildSys_abilityIdDisabled[a])
        set a = a +1
    endloop
    call DisplayTextToForce( GetPlayersAll(), "a = " + (I2S(a) ) )
    loop
        set h = GetHandleId( udg_buildSys_unit[i] )
        exitwhen h == 0
        call DisplayTextToForce( GetPlayersAll(), "i = " + (I2S(i) ) )
        set j = 0
        loop
            set aId =  udg_buildSys_abilityId[j]
            exitwhen aId == 0
            call DisplayTextToForce( GetPlayersAll(),  "j = " + ( I2S(j) ) )
            set n = i * a + j
            set bNum = udg_buildSys_integer[n]
            call SaveInteger(udg_hash_buildSys, h, aId, n)
            call SaveInteger(udg_hash_buildSys, n, 0, bNum)
            call SaveInteger(udg_hash_buildSys, n, 1, udg_buildSys_uType[n])
            set b = 0
            loop
                exitwhen udg_buildSys_real[bNumTotal * 3 + b] == 0
                call DisplayTextToForce( GetPlayersAll(),  "b = " + ( I2S(b) ) )
                call SaveReal(udg_hash_buildSys, n, 2 + b, udg_buildSys_real[bNumTotal * 3 + b])
                set b = b +1
            endloop
            set bNumTotal = bNumTotal + bNum + 1
            set j = j + 1
        endloop
        set i = i +1
    endloop
endfunction

//===========================================================================
function InitTrig_buildSys_store_loops_Copy_2 takes nothing returns nothing
    set gg_trg_buildSys_store_loops_Copy_2 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_buildSys_store_loops_Copy_2, function Trig_buildSys_store_loops_Copy_2_Actions )
endfunction

PS. Solved, thanks to Zwiebelchen.
 

Zwiebelchen

Hosted Project GR
Level 35
Joined
Sep 17, 2009
Messages
7,236
Sorry what? variable a in the store trigger isn't related to the other loops, it's just for saving dummy abilities to the real abilities. Later in the load when you use the ability it's removed and the dummy ability is added instead, it doesn't really have anything to do with the other loops :c
a gets incremented to 3 in the first loop, then remains 3 for the other loops. While it doesn't get changed at this point, it still appears in your setting of n.
You might want to change that to 3 instead, so that adding more abilities will not screw up your saving.
 
Level 12
Joined
Nov 3, 2013
Messages
989
a gets incremented to 3 in the first loop, then remains 3 for the other loops. While it doesn't get changed at this point, it still appears in your setting of n.
You might want to change that to 3 instead, so that adding more abilities will not screw up your saving.

Yeah I see what you mean, but isn't it the case that it won't "screw it up" but make it work? Since a is basically the max index for aId.

If you take a look at the exitwhen(s) it's made so that it loops until the variable doesn't have any value so I can just keep adding as I go. Obviously I wouldn't make some kind of system for just a few variables :c
 

Zwiebelchen

Hosted Project GR
Level 35
Joined
Sep 17, 2009
Messages
7,236
Yeah I see what you mean, but isn't it the case that it won't "screw it up" but make it work? Since a is basically the max index for aId.

If you take a look at the exitwhen(s) it's made so that it loops until the variable doesn't have any value so I can just keep adding as I go. Obviously I wouldn't make some kind of system for just a few variables :c
Sure thing. I was just explaining what I meant with "it sets the new max index for the system".
 
Status
Not open for further replies.
Top