1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

RemoveLocation question

Discussion in 'World Editor Help Zone' started by Sk0gsHu[GG]arN, Sep 14, 2019.

  1. Sk0gsHu[GG]arN

    Sk0gsHu[GG]arN

    Joined:
    Jul 4, 2007
    Messages:
    89
    Resources:
    0
    Resources:
    0
    Hi, I'm just wondering if I always have to remove locations in the same trigger like this
    • Set tempLoc = (Position of unit)
    • Special Effect - Create a special effect at tempLoc using Abilities\Spells\Human\MassTeleport\MassTeleportTarget.mdl
    • Custom script: call RemoveLocation(udg_tempLoc)
    • Set tempLoc = (Position of unit2)
    • Unit - Move unit instantly to tempLoc
    • Custom script: call RemoveLocation(udg_tempLoc)

    Or could I simply do it like this?
    • Set tempLoc = (Position of unit)
    • Special Effect - Create a special effect at tempLoc using Abilities\Spells\Human\MassTeleport\MassTeleportTarget.mdl
    • Set tempLoc = (Position of unit2)
    • Unit - Move unit instantly to tempLoc
    • Custom script: call RemoveLocation(udg_tempLoc)
     
    Last edited: Sep 14, 2019
  2. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    2,905
    Resources:
    1
    Spells:
    1
    Resources:
    1
    You need to remove it before you overwrite the variable. The first one.
     
  3. Cespie

    Cespie

    Joined:
    May 21, 2019
    Messages:
    344
    Resources:
    0
    Resources:
    0
    The first example is the correct one.
    Think of the variable as a name or reference. It isn't actually the location itself, it's just a way to refer to it.
    This means, that when you run "Set tempLoc = (Position of unit)", you are creating a position, and using tempLoc as a reference for it, lets call it "location 1".
    Now, if you were to run "Set tempLoc = (Position of unit2)", you are now creating a new position (location 2), and using the tempLoc name as a reference for it.
    The current situation is that you have 2 locations, location 1 and location 2, and you have 1 reference, tempLoc, which refers to Location 2. If you remove "tempLoc", you remove location 2, but not location 1, since that is no longer referred to as tempLoc. In fact, you don't really have a reference to Location 1 at all anymore, so it has essentially become a "memory leak", meaning a useless object cluttering up the game's memory, that you can't clean up anymore. It is possible to clean stuff like this automatically with LUA now, but I personally prefer keeping a bit of distance from that until the first movers like DSG can iron out potential issues.
     
  4. Wrda

    Wrda

    Joined:
    Nov 18, 2012
    Messages:
    1,100
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Just like it is possible with vjass. But still pointless. Either remove them manually, or move to (v)jass or lua.
     
  5. Sk0gsHu[GG]arN

    Sk0gsHu[GG]arN

    Joined:
    Jul 4, 2007
    Messages:
    89
    Resources:
    0
    Resources:
    0
    I see, very good explaination! Thanks
     
  6. JsonDalao

    JsonDalao

    Joined:
    Aug 6, 2019
    Messages:
    64
    Resources:
    0
    Resources:
    0
    Lua cannot automatically clear War3 object.
    Version 1.31 I seem to find that Lua is a variable that does not automatically drain Lua objects and discard them, so I need to turn on the timer and manually recycle them
     
    Last edited: Sep 24, 2019
  7. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    2,905
    Resources:
    1
    Spells:
    1
    Resources:
    1
  8. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,547
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    The script has some issues, but not ones that could not eventually be solved if people cared. For example hashtable references.
     
  9. JsonDalao

    JsonDalao

    Joined:
    Aug 6, 2019
    Messages:
    64
    Resources:
    0
    Resources:
    0
    HT reference object is not excreted? Or will it drain the object referenced in HT? (HT=HashTable)
     
  10. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,547
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Hashtables do not hold references to the Lua wrappers. As such it may incorrectly destroy objects stored in hashtable which are still accessible as there are no Lua references to them so the Lua wrapper is garbage collected but the object itself is still reachable from the hashtable.

    For reference the behaviour is such that if an object is placed inside a hashtable and the wrapper is still alive then the same wrapper will be returned as was used to place the object inside the hashtable. However if garbage collection were to run between placing the object in the hashtable and retrieving it then the wrapper may be destroyed if no Lua references to it exist in which case the retrieval operation will return a brand new wrapper object.

    This is where my garbage collector breaks because it will incorrectly destroy the object as it ties the object life to that of the Lua wrapper. The object may then be returned in future but has been destroyed. The theoretical solution is to proxy hashtable functions so that they can keep an Lua reference to the wrapper.
     
  11. JsonDalao

    JsonDalao

    Joined:
    Aug 6, 2019
    Messages:
    64
    Resources:
    0
    Resources:
    0
    Dr Super Good Can I use a table instead of hashtable?Is this not have a problem?
     
  12. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,547
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Yes that will not have a problem as Lua tables do keep Lua wrapper objects alive. One could in theory replace hashtable with a custom implementation that internally uses table and it would work.

    Jass arrays may also have a similar issue. They can be replaced with tables as well working in list mode.
     
  13. JsonDalao

    JsonDalao

    Joined:
    Aug 6, 2019
    Messages:
    64
    Resources:
    0
    Resources:
    0
    I have one more question. How to solve the problem of out of sync by traversing a string as the index of Table?
    Dr Super Good
     
  14. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,547
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    This is a problem? As long as the mapping was not set locally I do not see why it should cause an OoS.
     
  15. JsonDalao

    JsonDalao

    Joined:
    Aug 6, 2019
    Messages:
    64
    Resources:
    0
    Resources:
    0
    Is "in pairs" working locally?so,It will out of sync.right?
     
  16. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,547
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    I am not sure what you are asking. OoS only happens if the game state deviates enough that a checksum mismatch occurs between two or more clients.

    Running code locally will not cause a checksum mismatch unless it changes the synchronized game state locally.
     
  17. JsonDalao

    JsonDalao

    Joined:
    Aug 6, 2019
    Messages:
    64
    Resources:
    0
    Resources:
    0
    Dr Super Good I tested it with a couple of friends, and it's true that traversing a table using a string as an index is asynchronous because the order in which the strings are indexed is arranged on each client, so the data in the same index on each player's table may be different.
     
  18. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,547
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    I think I get what you are saying. Creating an iterator for all key value pairs in a table returns an iterator that operates in internal order and that internal order is not synchronous between clients and so the order the mappings are iterated is not synchronous and can cause OoS. I will speak with William about it.
     
  19. JsonDalao

    JsonDalao

    Joined:
    Aug 6, 2019
    Messages:
    64
    Resources:
    0
    Resources:
    0
    Please let me know if you have a solution,thanks~
     
  20. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,547
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Have you tried sorting the iterator into a list and then iterating the list? Slow but may be a work around if it works.