ScriptUO

Scripting Resources & Utilities => Orion UO Client => Topic started by: Bulldog on June 06, 2022, 02:17:35 AM

Title: Help! Casting string array elements to integers
Post by: Bulldog on June 06, 2022, 02:17:35 AM
Hello everyone I hope someone can help with this ..

I have a function that is returning durability on items as elements of an array these come out as arrayelement

eg:

 int numberx = Integer.parseInt(arrayelement
 int numbery = Integer.parseInt(arrayelement[y]);
Title: Re: Help! Casting string array elements to integers
Post by: altiric on June 06, 2022, 04:39:36 AM
Orion gives you: pairIntInt.Index, pairIntInt.Value, pairIntString.Index, and pairIntString.Text to work with.
Title: Re: Help! Casting string array elements to integers
Post by: Ali on October 31, 2022, 05:49:03 PM
Necroing a thread a bit, but figure I'd throw in a solution for this for anyone looking. In JavaScript there's a few options for changing a string to an integer. Number('1') and +'1' both work pretty much identically.

As for actually grabbing the durability values, RegEx is the way to go.

Code: [Select]
function DurabilityTest()
    {
    Orion.WaitForAddObject('myTarget');
    Orion.Print(GetDurability('myTarget'));
    }

function GetDurability(objSerial)
    {
    var obj = Orion.FindObject(objSerial);
    var durabilityArr = obj.Properties().match(/Durability (\d+) \/ (\d+)/) //evaluates to e.g., ['Durability 250 / 255', '250', '255'] OR null if match isn't found
    if(!durabilityArr) //if a match isn't found returns false
        return false;
    var minDurability = +durabilityArr[1]; //convert string to int
    var maxDurability = Number(durabilityArr[2]); //convert string to int
    return [minDurability, maxDurability]; //e.g. [250, 255]
    }