The Return Bug problem

NineClick

New Member
Reaction score
11
does anyone know how to remake this function? it uses return bug. i don't want to use hashtable so i'm still using game cache.

JASS:
function TheUnit takes string S1,string S2 returns unit
    return GetStoredInteger(udg_Cache,S1,S2)
    return null
endfunction


i'm ok with the return integer. my problem now is when returning a unit, group, etc. pls help. thanks. +rep. :thup:
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Change it to hashtable.

If you don't know about it, post your storage system here.
So that it can be fixed asap.
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
Use Hashtables. They are faster anyways and you can directly get the Unit out of it without the need of a return bug function.

The functions for hashtables are almost the same as with GCs, so there's no point to stick to GCs.

JASS:

call LoadUnitHandle(hashname, I1, I2)
call SaveUnitHandle(hashname, I1, I2, YourUnit)
call FlushChildHashtable(hashname, I1)
call RemoveSavedHandle(hashname, I1, I2)
call HaveSavedHandle(hashname, I1, I2)

Just switch your String based storing to integer based and you are done.
 

NineClick

New Member
Reaction score
11
i dunno how to use hashtable,still not familiar with it. i'm currently working on it though. ... how do you change my code without using hashtable? its ok if its going to be a two separate functions. because i need that code to call a unit using a string. pls help. tnx.
 

NineClick

New Member
Reaction score
11
ok .. so here's my code, from storing to getting the data. anyone?.. pls help.

The functions below are Custom Code Script: (These are the codes that need to be changed.)

JASS:
function H2I takes handle H1 returns integer
    return GetHandleId(H1)
endfunction

function H2Tx takes handle H2 returns string
    return I2S(H2I(H2))
endfunction

function SetHandle takes string table,string key,handle data returns nothing
    call StoreInteger(udg_Cache,table,key,H2I(data))
endfunction

function GetUnit takes string S1,string S2 returns unit
    return GetStoredInteger(udg_Cache,S1,S2)
    return null
endfunction

function GetGroup takes string S3,string S4 returns group
    return GetStoredInteger(udg_Cache,S3,S4)
    return null
endfunction



The functions below are how i store and get the data:

This function gets the data:
JASS:
function Fight takes unit UN1,unit UN2 returns nothing
    local string STN=H2Tx(UN1)
    local group LKH=GetGroup(STN,"Defenders") //this gets the group stored.
    local unit LKG=GetUnit(STN,"Attacker")//this gets the unit stored.
    if(LKG!=pKg)and(LKG!=null)then
	call Amfufu(LKH)
    ///... the rest are some codes.
endfunction


These functions store the data:
JASS:
function Attack takes nothing returns nothing
    call Fight(GetOrderTargetUnit(),GetTriggerUnit())
endfunction

function Unit takes unit UN returns nothing
    local group GRP
    local trigger TRG
    local string STR=H2Tx(UN)
    set GRP=CreateGroup()
    call SetHandle(STR,"Defenders",GRP)
    set TRG=CreateTrigger()
    call SetHandle(STR,"OnAttackOrder",TRG)
    call TriggerRegisterUnitEvent(TRG,UN,EVENT_UNIT_ISSUED_TARGET_ORDER)
    call TriggerAddAction(TRG,function Attack)
endfunction

function Defend_Action takes nothing returns nothing
    call Unit(GetTriggerUnit())
endfunction

function InitTrig_Defend takes nothing returns nothing
    set gg_trg_Defend =CreateTrigger()
    call TriggerRegisterEnterRectSimple(gg_trg_Defend,GetWorldBounds())
    call TriggerAddAction(gg_trg_Defend ,function Defend_Action)
endfunction
 

Artificial

Without Intelligence
Reaction score
326
Create a hashtable variable called Hashtable, and initialize it with a new hashtable. Then just replace your SetHandle, GetUnit, and GetGroup with these:

JASS:

function SetHandle takes string table, string key, agent data returns nothing
    call SaveAgentHandle(udg_Hashtable, StringHash(table), StringHash(key), data)
endfunction

function GetUnit takes string S1, string S2 returns unit
    return LoadUnitHandle(udg_Hashtable, StringHash(S1), StringHash(S2))
endfunction

function GetGroup takes string S3, string S4 returns group
    return LoadGroupHandle(udg_Hashtable, StringHash(S3), StringHash(S4))
endfunction


Should work, me thinks. ^_^
 

NineClick

New Member
Reaction score
11
still not working. .. anyone?.. please help with my code. +rep to those who can help. thanks.
 

Aedes

Member
Reaction score
8
Your code looks familiar. Hmmm. Anyways, return bug doesn't work anymore in 1.24b patch so you really have to use Hashtable. Hashtable is a better data storage than Game Cache. Well, for your code, it looks to me that your "SetHandle" function is the one converting the unit and group to integer and it stores it to your game cache (as integer of course). In this case, why don't you create an individual storage for your unit and group. Well at least you can get it or return it as a group and unit (and not as an integer), and still use the return bug.

For your unit and group storage:

JASS:
function SetGroup takes string table,string key,group grp returns nothing
    call SaveGroupHandle(udg_Hashtable,StringHash(table),StringHash(key),grp)
endfunction

function SetUnit takes string table,string key,unit unt returns nothing
    call SaveUnitHandle(udg_Hashtable,StringHash(table),StringHash(key),unt)
endfunction


To get the stored group and unit:

JASS:
function GetUnit takes string S1,string S2 returns unit
    return LoadUnitHandle(udg_Hashtable,S1,S2)
    return null
endfunction

function GetGroup takes string S3,string S4 returns group
    return LoadGroupHandle(udg_Hashtable,S3,S4)
    return null
endfunction


The H2Ix and H2Tx functions are fine. Do not use your SetHandle anymore. Ok.
 

NineClick

New Member
Reaction score
11
..wow. tnx dude. you gave me an idea on what to do. nwei, i'll try your code. tnx again. +rep! :thup:
 

Jesus4Lyf

Good Idea™
Reaction score
397
>Hmmm. Anyways, return bug doesn't work anymore in 1.24b patch
Sure it does.
JASS:
function ReturnI takes integer i returns integer
return i
endfunction
function NothingH takes Nothing returns handle
if false then
return null
endif
endfunction
function ReturnH takes handle h returns handle
return h
endfunction
function I2H takes integer i returns handle
call ReturnI(i)
return ReturnH(NothingH())
endfunction

Zomg. It are I2H. :D
(Don't use it. It are for me only. :p)
 

Aedes

Member
Reaction score
8
>Hmmm. Anyways, return bug doesn't work anymore in 1.24b patch
Sure it does.

It doesn't? .. But its ok to have two returns. Right? I thought it's working because it doesn't have any errors everytime I save it in WE. So if doesn't, then which of the two returns won't work?
 

Jesus4Lyf

Good Idea™
Reaction score
397
>So if doesn't, then which of the two returns won't work?
Having two returns has little or nothing to do with the return bug.

If you return twice, the first return will stop the function.

The return bug is about typecasting. There is a new(er) version of the return bug which I posted, just because it is still around. :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top