• 🏆 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] Storing Reals Not Working

Status
Not open for further replies.
Level 5
Joined
Sep 8, 2004
Messages
98
I put in some test triggers to see if it was working, but for some reason it isn't storing the real.

First I put in this line to test to see if the X and Y of the unit wasn't working right.:
Code:
    call DisplayTextToPlayer(Player(0),0,0,"X: " + R2S(GetUnitX(u)) + " Y: " + R2S(GetUnitY(u)))
into the SetTargLoc trigger, and it displays the unit's X and Y fine.

I also put in this line to test to see if it was storing it right.
Code:
	call DisplayTextToPlayer(Player(0),0,0,"X: " + R2S(GetStoredReal(udg_ordercache,I2S(H2I(u)),"X")) + " Y: " + R2S(GetStoredReal(udg_ordercache,I2S(H2I(u)),"Y")))

Only it just displays 0.000 for both the X and Y every time I select the unit.

Here are my triggers.

This is the auto-reorder trigger that's supposed to constantly order a unit to it's destination.
Code:
function AutoReorderUnits takes nothing returns nothing
    local group tempgroup = GetUnitsOfPlayerMatching(Player(11), null)
    local unit TEMP_Unit
    loop
        set TEMP_Unit = FirstOfGroup(tempgroup)
        exitwhen TEMP_Unit == null
        if GetOwningPlayer(TEMP_Unit) != Player(11) then
            call GroupRemoveUnit(tempgroup,TEMP_Unit)
        endif
    endloop
    loop
        set TEMP_Unit = FirstOfGroup(tempgroup)
        exitwhen TEMP_Unit == null
        call IssuePointOrder(TEMP_Unit,"attack",GetStoredReal(udg_ordercache,I2S(H2I(TEMP_Unit)),"X"),GetStoredReal(udg_ordercache,I2S(H2I(TEMP_Unit)),"Y"))
		call GroupRemoveUnit(tempgroup,TEMP_Unit)
    endloop
	call DestroyGroup(tempgroup)
	set tempgroup = null
endfunction
Code:
function InitTrig_AutoReorderUnits takes nothing returns nothing
    set gg_trg_AutoReorderUnits = CreateTrigger()
    call TriggerRegisterTimerEvent(gg_trg_AutoReorderUnits,2.00,true)
    call TriggerAddAction(gg_trg_AutoReorderUnits,function AutoReorderUnits)
endfunction


This is the SetTargLoc trigger. It runs, but It doesn't seem to store the reals.
Code:
function STL_Conditions takes nothing returns boolean
    return (GetOwningPlayer(GetOrderedUnit()) == Player(11) and GetIssuedOrderId() == String2OrderIdBJ("attack")) == true
endfunction

function SetTargLoc takes nothing returns nothing
    local unit u = GetOrderedUnit()
    local string id = I2S(H2I(u))
    call StoreReal(udg_ordercache,id, "X",GetUnitX(u))
    call StoreReal(udg_ordercache,id, "Y",GetUnitY(u))
    call DisplayTextToPlayer(Player(0),0,0,"X: " + R2S(GetUnitX(u)) + " Y: " + R2S(GetUnitY(u)))
    set u = null
endfunction

function InitTrig_SetTargLoc takes nothing returns nothing
    set gg_trg_SetTargLoc = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SetTargLoc, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
    call TriggerAddAction( gg_trg_SetTargLoc, function SetTargLoc )
    call TriggerAddCondition(gg_trg_SetTargLoc,Condition(function STL_Conditions))
endfunction

This is the test trigger to test storing of the X and Ys.
Code:
Test Trigs
    Events
        Player - Player 1 (Red) Selects a unit
    Conditions
        (Owner of (Triggering unit)) Equal to Player 12 (Brown)
    Actions
        Custom script:   call testH2I(GetTriggerUnit())

This is what is in my map script:

Code:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

function testH2I takes unit u returns nothing
	call DisplayTextToPlayer(Player(0),0,0,"X: " + R2S(GetStoredReal(udg_ordercache,I2S(H2I(u)),"X")) + " Y: " + R2S(GetStoredReal(udg_ordercache,I2S(H2I(u)),"Y")))
endfunction

Anyone know why storing reals isn't working?
 
Level 5
Joined
Sep 8, 2004
Messages
98
It's a native.

JASS:
native  GetStoredReal           takes gamecache cache, string missionKey, string key returns real

Thanks for the reply. :)

Although it doesn't have anything different than the code I already posted (since it is the full code), It's in order:

Map Script:
JASS:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

function testH2I takes unit u returns nothing
	call DisplayTextToPlayer(Player(0),0,0,"X: " + R2S(GetStoredReal(udg_ordercache,I2S(H2I(u)),"X")) + " Y: " + R2S(GetStoredReal(udg_ordercache,I2S(H2I(u)),"Y")))
endfunction

Auto Reorder Units:

JASS:
function AutoReorderUnits takes nothing returns nothing
    local group tempgroup = GetUnitsOfPlayerMatching(Player(11), null)
    local unit TEMP_Unit
    loop
        set TEMP_Unit = FirstOfGroup(tempgroup)
        exitwhen TEMP_Unit == null
        if GetOwningPlayer(TEMP_Unit) != Player(11) then
            call GroupRemoveUnit(tempgroup,TEMP_Unit)
        endif
    endloop
    loop
        set TEMP_Unit = FirstOfGroup(tempgroup)

        exitwhen TEMP_Unit == null
        call IssuePointOrder(TEMP_Unit,"attack",GetStoredReal(udg_ordercache,I2S(H2I(TEMP_Unit)),"X"),GetStoredReal(udg_ordercache,I2S(H2I(TEMP_Unit)),"Y"))
		call GroupRemoveUnit(tempgroup,TEMP_Unit)
    endloop
	call DestroyGroup(tempgroup)
	set tempgroup = null
endfunction

function InitTrig_AutoReorderUnits takes nothing returns nothing
    set gg_trg_AutoReorderUnits = CreateTrigger()
    call TriggerRegisterTimerEvent(gg_trg_AutoReorderUnits,2.00,true)
    call TriggerAddAction(gg_trg_AutoReorderUnits,function AutoReorderUnits)
endfunction

Set Targ Loc:
JASS:
function STL_Conditions takes nothing returns boolean
    return (GetOwningPlayer(GetOrderedUnit()) == Player(11) and GetIssuedOrderId() == String2OrderIdBJ("attack")) == true
endfunction

function SetTargLoc takes nothing returns nothing
    local unit u = GetOrderedUnit()
    local string id = I2S(H2I(u))
    call StoreReal(udg_ordercache,id, "X",GetUnitX(u))
    call StoreReal(udg_ordercache,id, "Y",GetUnitY(u))
    call DisplayTextToPlayer(Player(0),0,0,"X: " + R2S(GetUnitX(u)) + " Y: " + R2S(GetUnitY(u)))
    set u = null
endfunction

function InitTrig_SetTargLoc takes nothing returns nothing
    set gg_trg_SetTargLoc = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SetTargLoc, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
    call TriggerAddAction( gg_trg_SetTargLoc, function SetTargLoc )
    call TriggerAddCondition(gg_trg_SetTargLoc,Condition(function STL_Conditions))
endfunction

Testing Trigger:
JASS:
Test Trigs
    Events
        Player - Player 1 (Red) Selects a unit
    Conditions
        (Owner of (Triggering unit)) Equal to Player 12 (Brown)
    Actions
        Custom script:   call testH2I(GetTriggerUnit())
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
OOPS :oops: lol, wasnt thinking straight

uuh... i really cant c the problem ATM, but, 2 things

-number one, enclose ur JASS code in a JASS tag, its SOOOO much easier to read ( and still allows indenting )

-number two, try replacing GetOrderedUnit in SetTargLoc with GetTriggerUnit. even if this does not solve the problem, GetTriggerUnit will always run the fastest :p
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
JASS:
local unit u = GetOrderedUnit()

:?

( thats in the SetTargLoc function )

i think i have your problem. here it is - you ARE storing the values correctly... you just arent getting the right unit back...

Problem #1 -
in your Test Trigs trigger, since the event is a PLAYER event and does not reference units directly, Triggering Unit == null. you need some kind of Selected Unit or something.

Problem #2 -

In your Auto Reorder Units trigger, for the first loop, the group consists of only Player(11) units, therefore they are all removed, leading to a pointless function. replace that function with the following Updated one. ( also cleans up some messy BJ calls, etc, etc )

JASS:
function AutoReorderUnits takes nothing returns nothing
    local group tempgroup = CreateGroup()
    local unit TEMP_Unit
    call GroupEnumUnitsInRect( tempgroup, bj_mapInitialPlayableArea, null )
    loop
        set TEMP_Unit = FirstOfGroup(tempgroup)
        exitwhen TEMP_Unit == null
        if GetOwningPlayer( TEMP_Unit ) != Player(11) then
            call IssuePointOrder(TEMP_Unit,"attack",GetStoredReal(udg_ordercache,I2S(H2I(TEMP_Unit)),"X"),GetStoredReal(udg_ordercache,I2S(H2I(TEMP_Unit)),"Y"))
        endif
        call GroupRemoveUnit(tempgroup,TEMP_Unit)
    endloop
    call DestroyGroup(tempgroup)
    set tempgroup = null
endfunction
 
Level 5
Joined
Sep 8, 2004
Messages
98
Actually the GetTriggerUnit() was listed when I used it in the GUI as how you refer to the selected unit, since there is no GetSelectedUnit() or anything of the sort.

>>In your Auto Reorder Units trigger, for the first loop, the group consists of only Player(11) units, therefore they are all removed, leading to a pointless function. replace that function with the following Updated one. ( also cleans up some messy BJ calls, etc, etc )

Yeah, I had help on this trigger on another site, and they got it completely working. Thanks though :D . (This was one of the problems).

Another one of the things I did wrong with it, was I forgot to Init the Game Cache (Since I didn't know I needed to).

Here's the finished code:

JASS:
Map Script:

function H2I takes handle h returns integer
    return h
    return 0
endfunction

function testH2I takes unit u returns nothing
	call DisplayTextToPlayer(Player(0),0,0,"X: " + R2S(GetStoredReal(udg_ordercache,I2S(H2I(u)),"X")) + " Y: " + R2S(GetStoredReal(udg_ordercache,I2S(H2I(u)),"Y")))
endfunction

JASS:
AutoReorderUnits:

function AutoReorderUnits takes nothing returns nothing
    local group tempgroup = GetUnitsOfPlayerMatching(Player(11), null)
    local unit TEMP_Unit
    local string id
    call DisplayTextToPlayer(Player(0),0,0,"AutoReorderUnits Running")
    loop
        set TEMP_Unit = FirstOfGroup(tempgroup)
        exitwhen TEMP_Unit == null
        set id = I2S(H2I(TEMP_Unit))
        call IssuePointOrder(TEMP_Unit,"attack",GetStoredReal(udg_ordercache,id,"X"),GetStoredReal(udg_ordercache,id,"Y"))
        call GroupRemoveUnit(tempgroup,TEMP_Unit)
    endloop
	call DestroyGroup(tempgroup)
	set tempgroup = null
        set id = ""
endfunction

function InitTrig_AutoReorderUnits takes nothing returns nothing
    set gg_trg_AutoReorderUnits = CreateTrigger()
    call TriggerRegisterTimerEvent(gg_trg_AutoReorderUnits,2.00,true)
    call TriggerAddAction(gg_trg_AutoReorderUnits,function AutoReorderUnits)
endfunction

JASS:
SetTargLoc:

function STL_Conditions takes nothing returns boolean
    return (GetOwningPlayer(GetOrderedUnit()) == Player(11) and GetIssuedOrderId() == String2OrderIdBJ("attack")) == true
endfunction

function SetTargLoc takes nothing returns nothing
    local unit u = GetOrderedUnit()
    local string id = I2S(H2I(u))
    call StoreReal(udg_ordercache,id, "X",GetLocationX(GetOrderPointLoc()))
    call StoreReal(udg_ordercache,id, "Y",GetLocationY(GetOrderPointLoc()))
    set u = null
    set id = ""
endfunction

function InitTrig_SetTargLoc takes nothing returns nothing
    set gg_trg_SetTargLoc = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SetTargLoc, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
    call TriggerAddAction( gg_trg_SetTargLoc, function SetTargLoc )
    call TriggerAddCondition(gg_trg_SetTargLoc,Condition(function STL_Conditions))
endfunction
 
Status
Not open for further replies.
Top