Scripting Resources & Utilities > Orion UO Client

Help! Casting string array elements to integers

(1/1)

Bulldog:
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[x]/arrayelement[y] which is the durability say 234 / 255. I want to cast the strings into an integer but I am not sure what the Orion version of Integer.parseInt ?

eg:

 int numberx = Integer.parseInt(arrayelement[x]);
 int numbery = Integer.parseInt(arrayelement[y]);

altiric:
Orion gives you: pairIntInt.Index, pairIntInt.Value, pairIntString.Index, and pairIntString.Text to work with.

Ali:
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: ---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]
    }
--- End code ---

Navigation

[0] Message Index

Go to full version