R96 Lua update!

Discussion in 'Lua Discussions' started by DavidDC, Nov 17, 2021.

  1. DavidDC

    DavidDC Programmer Moderator SOTA Developer

    Messages:
    1,373
    Likes Received:
    2,957
    Trophy Points:
    113
    Gender:
    Male
    Hey guys!

    I have updated the Lua API with some more functionalities. You can check them out in the API Doc.

    Fixed that bug with multiple script which needed all global function to work and some more !

    Like before, i have made a little example of some of the new functionality like the input box and resizable panel.

    Release R96 is tomorrow but this new functionalities can be tested on QA.

    Code:
    --Here we have our table of object we want to create. Also used to save objectID and parentID (See the R95 LuaDemo example if you need more information about this)
    local _panels = {{ x = 400.0, y = 300.0, width = 300, height = 200, objectID = -1, parendID = -1}}
    local _inputs = {{ x = 30.0, y = 100.0, width = 200, height = 30, objectID = -1, parendID = -1}}
    local _texts = {{ text = "Hello world!", x = 30.0, y = 30.0, width = 200, height = 40, fontSize = 30, objectID = -1, parentID = -1 }}
    
    function ShroudOnStart()
        _panels[1].objectID = ShroudUIPanel(_panels[1].x,
                                             _panels[1].y,
                                             _panels[1].width,
                                             _panels[1].height);
        ShroudSetColor(_panels[1].objectID, UI.Panel, "#000000");
        
        ShroudSetResizable(_panels[1].objectID, UI.Panel); --Possible option are "Vertical", "Horizontal", "None", or not passing a 3rd argument at all will make both vertical and horizontal enabled with corner
        
        _texts[1].objectID = ShroudUIText(_texts[1].text,
                 _texts[1].fontSize,
                 _texts[1].x,
                 _texts[1].y,
                 _texts[1].width,
                 _texts[1].height,
                 _panels[1].objectID,
                 UI.Panel);
                
        ShroudRaycastObject(_texts[1].objectID, UI.Text, false); --Makes click go through the object
        ShroudSetColor(_texts[1].objectID, UI.Panel, "#FF0000"); --Change color of text since our panel is black
        
        _inputs[1].objectID = ShroudUIInput(_inputs[1].x,
                                             _inputs[1].y,
                                             _inputs[1].width,
                                             _inputs[1].height,
                                             _panels[1].objectID,
                                             UI.Panel);
    end
    --Here we return to console log whatever text was entered in the input field
    function ShroudOnInputChange(objectID, text)
        ConsoleLog(string.format("Text changed (%s)", text));
    end
     
    ngavarta, Cordelayne, Archer and 6 others like this.
  2. Tirrag

    Tirrag Avatar

    Messages:
    621
    Likes Received:
    1,296
    Trophy Points:
    93
    Location:
    Iowa, USA / Maiden's Blush, SotA
    FrostII likes this.
  3. DavidDC

    DavidDC Programmer Moderator SOTA Developer

    Messages:
    1,373
    Likes Received:
    2,957
    Trophy Points:
    113
    Gender:
    Male
    I might have missed the release date for the bug where window disapear when switching scene! Not sure why but some code magically appeared which decided to destroy that function ESPECIALLY when changing scene! I must have been sleeping while writing that.. lol
    It will be in first patch if this fix doesnt make release!
     
    Feldon Grimshaw, Anpu and FrostII like this.
  4. FrostII

    FrostII Bug Hunter

    Messages:
    5,644
    Likes Received:
    10,783
    Trophy Points:
    153
    Gender:
    Male
    Location:
    Pacific Northwest
    +1 :)
     
    Archer likes this.
  5. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    I have an object I've created at position 1100, 400. When I call GetPosition and access the x and y attributes of the vector, I'm getting 550, 400.
    I also ran it on an object created at 1000, 400 and it returned 550, 400.
    Ran it on an object created at 850, 400....and it returned 850, 400.

    And looking more into things....those first two objects were an input and a toggle object while the last one is a button. When I changed the button to 1450, 400, I got 1450, 400 for GetPosition.

    Also...an enhancement or for clarity if it already exists.....can something be added for resizable objects to return their new width and height?
     
  6. DavidDC

    DavidDC Programmer Moderator SOTA Developer

    Messages:
    1,373
    Likes Received:
    2,957
    Trophy Points:
    113
    Gender:
    Male
    ShroudGetPosition return the anchored position of the object, i have it set differently for input and toggle and im not totally sure as of why i have set it this way but ill look into it and maybe fix it if its wrong.
    And yeah i can add something to return the size width/length. Will be either in patch or next release!

    Thanks for feedback guys!
     
    FrostII likes this.
  7. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    Not sure if this is because of a recent change....but are the object ID numbers for objects automatically changing if one with a lower ID number is deleted?

    Now there may be a good reason for this, but it wasn't how it worked before.
     
  8. DavidDC

    DavidDC Programmer Moderator SOTA Developer

    Messages:
    1,373
    Likes Received:
    2,957
    Trophy Points:
    113
    Gender:
    Male
    Oh i think you are right, i made so many functions at once (i did test them) but never really went deep in testing with destroy function. It is actually removing an item from a list and yes, its breaking the IDs. Fixing that!

    Edit: Fixed!
     
    Last edited: Dec 6, 2021
  9. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    Input Objects:

    ShroudSetInputText does not appear to be working or I'm confused if I am using it right. I have a button that when pressed prints the text in the input box to the console, it then is supposed to clear the text in the input box. ShroudGetInputText works and the text prints. However, the input box does not clear. I'm using ShroudSetInputText(object,"") but even when I put something in the quotes it does not change.

    Secondly, I tried using ShroudSetFont on an input object but it does not appear to be changing the font size of inserted text. I can only get it to change if I use string.format manipulations.
     
  10. ngavarta

    ngavarta Avatar

    Messages:
    77
    Likes Received:
    56
    Trophy Points:
    8
    Awesome, I've get to learn the new APIs well, but not all giving a good examples,
    we only get R93, R95, and R96 examples like this one here only (if I'm not missing anything).

    What about other earlier introduced functions, will there be any supplement documentation/ example demonstrating how to use them?