Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Solved] LUA: Ascii typecasting on ObjectMerger

Discussion in 'Triggers & Scripts' started by Zwiebelchen, Jan 2, 2016.

  1. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    7,014
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    So... I was using LUA to auto-generate levels for a channel ability. The problem comes with two object data fields that are kind of unique in their implementation for the channel ability:

    'Ncl3' and 'Ncl2'; better known as "options" and "target type".
    These fields have checkboxes in GUI, allowing to select stuff like "visible" or "physical spell", or target types like "point target" or "self cast".

    If you use Ctrl+D to display the raw data for these fields, these options simply get reduced to integers, which should in theory make it easy to write into these fields with the ObjectMerger, right?
    Wrong!

    It seems that these fields are the only fields in the object editor that are not strings typecasted as integers, but actual integers.

    If I use object merger like this, to write the value 0 into the field:
    //! i makechange(current, "Ncl3", "1", "0")

    It actually writes 48, which is the ascii equivalent of the character "0".

    If I do this:
    //! i makechange(current, "Ncl3", "1", 0)

    then the same thing happens.

    It seems that whatever I put into the field, object merger will typecast it to a string (and then back to integer), offsetting the input value by the ascii equivalent. Is there a way to prevent this? Or a clever exploit to trick the calculation into putting actual zero into the data field?
    Can I use hex like
    0x00
    in object merger?
     
  2. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    7,014
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    Hah! Zwiebelchen vs. Object editor 1:0!

    //! i makechange(current, "Ncl3", "1", string.char("0")) 


    I have no idea why this works, but it does.
     
  3. EdwardElric

    EdwardElric

    Joined:
    Jun 19, 2010
    Messages:
    49
    Resources:
    0
    Resources:
    0
    Nice workarround! But wait!

    I have identical problem with builder unit 'hpea' with object editor field "uaen". When I generate with following LUA code, this field is set to value 48:
    Code (vJASS):
    scope GenCustomObjectData

    //! runtextmacro GENERATE_OBJECTS()

    //! textmacro GENERATE_OBJECTS
    //! externalblock extension=lua ObjectMerger $FILENAME$

    //! i function set(field, value)
    //! i     makechange(current, field, value)
    //! i end

    //! i setobjecttype("units")
    //! i createobject("hpea", "1d1A");   resetobject(current);   createobject("hpea", "1d1A"); set("uaen", 0);

    //! endexternalblock
    //! endtextmacro GENERATE_OBJECTS

    endscope

    also for:
    Code (vJASS):
    ...
    //! i createobject("hpea", "1d1A");   resetobject(current);   createobject("hpea", "1d1A"); set("uaen", "0");
    ...


    That was already expected, so when I use your workarround like:
    Code (vJASS):
    //! i createobject("hpea", "1d1A");   resetobject(current);   createobject("hpea", "1d1A"); set("uaen", string.char("0"));

    It only works temporary!
    What that means?!
    - i activate LUA object generation in trigger, save map & close world editor
    - start world editor, load map & deactivate LUA object generation in trigger => when i look into object editor & select '1d1A', it correctly shows 0 under field "uaen"
    - save map => now when i look into object editor & de- & reselect '1d1A', it shows default value under field "uaen" which is 3 for units based on 'hpea'!
    - even when i close map & WE and reload WE & map, the field stays on default value... so still i have no fix for this :-(

    Hmmm... Zwiebelchen vs. Object editor 1:1!
     
    Last edited: Sep 11, 2016
  4. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    7,014
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    There is an unofficial pjass update around here somewhere that fixes these issues (and also fixes some other LUA bugs).
    Unfortunately, I don't have a link for it. You should find it via searching, though.
     
  5. WaterKnight

    WaterKnight

    Joined:
    Aug 18, 2009
    Messages:
    4,035
    Resources:
    5
    Maps:
    1
    Tutorials:
    4
    Resources:
    5
    What has that to do with pjass?
     
  6. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,537
    Resources:
    23
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    5
    JASS:
    3
    Resources:
    23
  7. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    3,788
    Resources:
    1
    Spells:
    1
    Resources:
    1
    What are these
     //! i <whatever>
    lines? Never seen 'em before. LUA script?
     
  8. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,537
    Resources:
    23
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    5
    JASS:
    3
    Resources:
    23
    Yeh, Lua Object Generation.
     
  9. WaterKnight

    WaterKnight

    Joined:
    Aug 18, 2009
    Messages:
    4,035
    Resources:
    5
    Maps:
    1
    Tutorials:
    4
    Resources:
    5
    The
    //! i 
    are for lines inside an
    //! externalblock
    . jasshelper writes them to a file and passes the file to the specified tool. Since mostly only the grimext tools are shipped as external tools in JNGP, which use Lua as an interface, you will most likely only see Lua there.
     
  10. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    7,014
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    Yes, that was the hotfix I was talking about. Use that; it works!
     
  11. EdwardElric

    EdwardElric

    Joined:
    Jun 19, 2010
    Messages:
    49
    Resources:
    0
    Resources:
    0
    @ IcemanBo, Zwiebelchen:
    The ObjectMerger Hotfix from PitzerMike for the Channel ability?
    Wc3C.net - View Single Post - Grim Extension Pack
    Well, I'm already using the hotfix, and it also works for the channel ability, but sadly not for the worker unit 'hpea' under field "uaen"...

    I replied in the thread "Lua Object Generation" from PurgeandFire for reporting this bug & for getting help in understanding ObjectMerger source code:

    Lua Object Generation
     
  12. Wietlol

    Wietlol

    Joined:
    Aug 1, 2013
    Messages:
    4,638
    Resources:
    3
    Spells:
    3
    Resources:
    3
    I already reported the attacks enabled thing.
    I assume this is the same for every other dropdown.