![]() |
String Parsing
Say I had an editable text box and when the person entered a number in it I needed the number for something like:
if(player.gralats = "Params[1] * 15") { Would their be anyother way to do it then string parsing , or would anyone like to explain to me in detail about string parsing? -Thanks in advance Toxen |
Not sure what you're asking.
If you only want it to display the first 15 characters then you can do: params[1].substring(0, 15) if you want to cut off the first 15 characters you can do: params[1].substring(15) If you want to cut off all the characters before "15" you can do: params[1].substring(params[1].pos(15)) Also you should use == for comparison. Using one = is for declaration. if (player.rupees == params[1].substring(15)) { for example. If you just need to parse a string you could do: params = obj.text.tokenize(); then use params[0] for the first space. You can define which character to parse like this: params = obj.text.tokenize("a"); if obj.text = "123abc123abc"; params[0] would = 123 params[1] would = bc123 and so on. |
PHP Code:
|
Well Tig, I'm wondering how to take in the text and then use it right after in the same event, like I have an edit able text area and they put a number in there to see how many packages of that item, they'd like so it's not like a set text yet, so how would I do it?
|
Quote:
function Obj.onAction() { player.chat = "I typed in" SPC obj.text; } |
I believe he's trying to do something like so:
PHP Code:
|
Chompy released a parser like this, and I released one a while back.
|
Kinda difficult when dealing when []'s and such but still possible.
|
substring(0, 15)
hehe...I learned this in VB today. ^^ ~Aeko...slowly understanding scripts letter by letter~ |
Quote:
text*15 or float(text)*15 should suffice, but if there's something I'm missing here, might I recommend this script (though I hate to plug my own script >_<). It has the necessary code to do this, probably PHP Code:
Though, I'm willing to help make a limited eval() if there is enough demand for it. |
Quote:
|
Quote:
I've started a parser that is suppose to parse math stuff like 1+1, a+1=2 etc. but I got bored with it and couldn't decide if I wanted to include variables or not and a lot of other stuff.. |
Toxen, you could do something like this (although there are a few ways):
NPC Code: and certainly better ways if you're planning on making a calculator or so. |
It's funny because my programming assignment for this week is to make a calculator that converts an in-fixed expression to a post-fixed expression and then calculates the post-fixed expression and returns the result.
Probably that method would be the best for an eval() also. I guess I could make one when I do my assignment on Friday (due date, duh). Oh it also involves stacks. |
Email Google, ask for theirs, then convert it to GS2 :D
|
Quote:
|
Quote:
PHP Code:
|
Quote:
http://www.google.com/help/calculator.html Anyhow, it sounds to me like Toxen is just asking how to use a string number in calculations, if that is the case then Graal converts it automatically. newnumber = TextEditObject.text * 5; |
Quote:
|
I actually used
[PHP] temp.arr = params[0].tokenize(); for (temp.i=0; temp.i<temp.arr.size(); temp.i++) { temp.arr[temp.i] = int(temp.arr[temp.i]); } and it worked so. |
1 Attachment(s)
Quote:
Quote:
I would perhaps make this a class and join it to a static variable. PHP Code:
|
Dangerous to use eval for assignment or modification of variables though.
|
Quote:
|
Quote:
|
I've updated the script above:
I wonder if I should finish it? Would eval be beneficial to anyone? Does anyone need it to do something particular? |
Thank you all so much, and especially to you pfa, that is a pretty nice script.
|
Quote:
This guy I like :D |
Quote:
|
Quote:
|
|
| All times are GMT +2. The time now is 05:57 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.