• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Jass function crashs the game!!!

Status
Not open for further replies.
Level 2
Joined
Nov 8, 2007
Messages
19
hi,

i ve written a function that should stor an integer value of an item in gamecache, but only if the value "place" is = 00 (free)
i start the function when a unit gets an item.
i have to say that im very nooby in jass, and i cant find the mistake!!

here the function:
JASS:
function GetItem takes item it, unit u returns nothing
    local integer id = GetItemTypeId(it)
    local integer playerid = H2I(GetOwningPlayer(u)) 
    local integer i = 0
    local boolean slotfree = false
    
    loop
    exitwhen i == InitInv_maxsize()
    if(GetStoredInteger(GC(), I2S(playerid + i), "SlotItem") == 0 ) then
        call StoreInteger(GC(), I2S(playerid + i ), "SlotItem", id )
        set slotfree = true
    endif
    set i = i + 1
    endloop
    if(slotfree == false) then
        call  DisplayTextToForce(GetForceOfPlayer(GetOwningPlaye
r(u)), "|cffCC0000 You have no free Inventory Slot!! |r" )
        call CreateItemLoc(id, GetUnitLoc(u) )
    endif
endfunction

InitInv_maxsize() is a constant that returns an integer value (64)

there are no syntax errors!

i hope somebody can help me pls!!!
 
Last edited by a moderator:
Level 5
Joined
Oct 27, 2007
Messages
158
hi,

i ve written a function that should stor an integer value of an item in gamecache, but only if the value "place" is = 00 (free)
i start the function when a unit gets an item.
i have to say that im very nooby in jass, and i cant find the mistake!!

here the function:
JASS:
globals
    constant integer inv_size = 64 // if the value is constant do this
    gamecache gc = InitGameCache("yourgamecache.w3v")
endglobals

function GetItem takes item it, unit u returns nothing
    local integer id = GetItemTypeId(it)
    local integer player_inv = GetPlayerId(GetOwningPlayer(u))  * inv_size
    local integer i = 0
    local boolean slotfree = false
    
    loop
        exitwhen i == inv_size or slotfree // I think this is what you want
        if StoredInteger(gc, I2S(player_inv + i), "SlotItem") == 0 then
            call StoreInteger(gc, I2S(player_inv + i ), "SlotItem", id )
            set slotfree = true
        endif
        set i = i + 1
    endloop
    if not slotfree then
        call  DisplayTextToForce(GetForceOfPlayer(GetOwningPlayer(u)), "|cffCC0000 You have no free Inventory Slot!! |r" )
        call CreateItem(id, GetUnitX(u), GetUnitY(u)) //Locations have to be removed. If not it'll leak memory. This way you won't need a location.
    endif
endfunction
InitInv_maxsize() is a constant that returns an integer value (64)

there are no syntax errors!

i hope somebody can help me pls!!!

Fixed a location leak and some code cleaning. Do you want to store an item id 64 times for one player? It seems rather strange. Furthermore you're using a strange method of storing items unique for a player. You're referencing the handle index of a player. If the handles are close together then it's quite possible that you overwrite other player's items. Just reserve a unique range as mission key for each player so it won't have a chance of overlapping.

If it still crashes then post the calling function of this function as well.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Not you, the original poster. I know "why" he is doing it, but I don't see why you wouldn't just use PlayerId (H2I is unstable enough for temporary handles, using it for this sort of thing is just... odd, especially since gamecache here probably means he is using it in other places as well).
 
Level 5
Joined
Oct 27, 2007
Messages
158
Not you, the original poster. I know "why" he is doing it, but I don't see why you wouldn't just use PlayerId.

Isn't it obvious he's trying to store items unique to a player. Like I said he's not using the right method of doing so...
 
Level 2
Joined
Nov 8, 2007
Messages
19
thx. for answers.

i knew the memory leak in location but i forget to remove it. thx!

i dont know, ion the normal worldeditor this function is bugless. but in jassnewgen (i use this we normaly) it crashs the game.....

confused....

but this problem confuses me much more.....
one function
JASS:
function Test takes nothing returns nothing
call StoreInteger(GC(), "5", "5", 5)
call DisplayTextToForce(GetForceOfPlayer(Player(0)), GetStoredInteger(GC(), "5", "5") )
endfunction

why does this function sends a message to player 1 called "0".

jass is only confusing shit......
 
Level 5
Joined
Oct 27, 2007
Messages
158
thx. for answers.

i knew the memory leak in location but i forget to remove it. thx!

i dont know, ion the normal worldeditor this function is bugless. but in jassnewgen (i use this we normaly) it crashs the game.....

confused....

but this problem confuses me much more.....
one function
JASS:
function Test takes nothing returns nothing
call StoreInteger(GC(), "5", "5", 5)
call DisplayTextToForce(GetForceOfPlayer(Player(0)), GetStoredInteger(GC(), "5", "5") )
endfunction
why does this function sends a message to player 1 called "0".

jass is only confusing shit......


Did you try the suggestion I made?
Why use a GC function to get the gamecache?
What does the function GC look like?
I think you have a problem with the cache not being initialized properly.
 
Level 5
Joined
Oct 27, 2007
Messages
158
If GC is not initialized, it just returns null values, and shouldn't crash the game.

Non existing integers will return 0 when trying to read them. The example he tried shows that. To me it still seems that the cache is not properly set up.

By the way, Drone, for the range of values, simply used the second string index provided for GC?

Works fine for accessing a player's inventory too. I just followed the idea of the TS. Maybe he wants to have the slots numbered and have a way of identifying what each slot holds.
 
Level 5
Joined
Oct 27, 2007
Messages
158
yeah. forget to initialize the gamecach... now it works!!



just tell me, what is the right method?


I already told you that. Did you try my suggestion...
You can use key string indexing only like PP said, or use mission key, key indexing. I'd prefer the latter if I wanted to store additional information like slot type, in a referencing way.
 
Status
Not open for further replies.
Top