Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-20-2008, 12:11 AM
Toxen Toxen is offline
A Toxic Fellow
Join Date: Jan 2008
Location: Georgia
Posts: 36
Toxen is on a distinguished road
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
__________________
UN NAT.
Reply With Quote
  #2  
Old 03-20-2008, 12:17 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
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.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #3  
Old 03-20-2008, 12:39 AM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
PHP Code:
temp.strVar "42";
temp.intVar int(temp.strVar); 
Reply With Quote
  #4  
Old 03-20-2008, 12:40 AM
Toxen Toxen is offline
A Toxic Fellow
Join Date: Jan 2008
Location: Georgia
Posts: 36
Toxen is on a distinguished road
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?
__________________
UN NAT.
Reply With Quote
  #5  
Old 03-20-2008, 01:59 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by Toxen View Post
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?
obj.text

function Obj.onAction() {
player.chat = "I typed in" SPC obj.text;
}
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #6  
Old 03-20-2008, 02:14 AM
Programmer Programmer is offline
Coder
Programmer's Avatar
Join Date: Jan 2008
Location: -78.464422, 106.837328
Posts: 449
Programmer has a spectacular aura aboutProgrammer has a spectacular aura about
Send a message via AIM to Programmer Send a message via MSN to Programmer Send a message via Yahoo to Programmer
I believe he's trying to do something like so:

PHP Code:
temp.var1 4;
temp.str "temp.var1 + 1";
temp.value int(temp.str);

echo(
temp.value);

// he wants it to return 5, but it returns -1, naturally. 
Would be interesting to figure this out. Graal needs an eval() function.
__________________
- Iᴀɴ Zɪᴍᴍᴇʀᴍᴀɴ
Reply With Quote
  #7  
Old 03-20-2008, 02:25 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Chompy released a parser like this, and I released one a while back.
__________________
Reply With Quote
  #8  
Old 03-20-2008, 05:32 AM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Kinda difficult when dealing when []'s and such but still possible.
__________________
Do it with a DON!
Reply With Quote
  #9  
Old 03-20-2008, 06:06 AM
Clockwork Clockwork is offline
ᶘ ᵒᴥᵒᶅ...ᶘ ಠᴥಠᶅ❤...ℳℴℯ
Clockwork's Avatar
Join Date: Feb 2007
Location: Pennsylvania
Posts: 2,071
Clockwork has a brilliant futureClockwork has a brilliant futureClockwork has a brilliant futureClockwork has a brilliant futureClockwork has a brilliant futureClockwork has a brilliant futureClockwork has a brilliant futureClockwork has a brilliant future
substring(0, 15)

hehe...I learned this in VB today.

~Aeko...slowly understanding scripts letter by letter~
__________________
Reply With Quote
  #10  
Old 03-20-2008, 09:57 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by Programmer View Post
I believe he's trying to do something like so:

PHP Code:
temp.var1 4;
temp.str "temp.var1 + 1";
temp.value int(temp.str);

echo(
temp.value);

// he wants it to return 5, but it returns -1, naturally. 
Would be interesting to figure this out. Graal needs an eval() function.
I don't see why we need to parse a string if we're doing simple math...
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:
temp.result where_param_format("","",whatever_text,15,"times"); 
Not totally sure on this though.

Though, I'm willing to help make a limited eval() if there is enough demand for it.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/

Last edited by Tolnaftate2004; 03-20-2008 at 10:19 AM..
Reply With Quote
  #11  
Old 03-20-2008, 12:13 PM
Programmer Programmer is offline
Coder
Programmer's Avatar
Join Date: Jan 2008
Location: -78.464422, 106.837328
Posts: 449
Programmer has a spectacular aura aboutProgrammer has a spectacular aura about
Send a message via AIM to Programmer Send a message via MSN to Programmer Send a message via Yahoo to Programmer
Quote:
Originally Posted by Tolnaftate2004 View Post
I don't see why we need to parse a string if we're doing simple math...
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:
temp.result where_param_format("","",whatever_text,15,"times"); 
Not totally sure on this though.

Though, I'm willing to help make a limited eval() if there is enough demand for it.
From what he told me, he's trying to make a text box and allow people to input simple mathematics and variables, and then translate them to return a readable value. The script I posted was merely an example of what he essentially wants done.
__________________
- Iᴀɴ Zɪᴍᴍᴇʀᴍᴀɴ
Reply With Quote
  #12  
Old 03-20-2008, 02:29 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Programmer View Post
From what he told me, he's trying to make a text box and allow people to input simple mathematics and variables, and then translate them to return a readable value. The script I posted was merely an example of what he essentially wants done.
But if that was possible, making a calculator in a programming language would be easy as pie..

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..
__________________
Reply With Quote
  #13  
Old 03-20-2008, 05:58 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Toxen, you could do something like this (although there are a few ways):
NPC Code:

if (obj.text.pos("*") > 0) {
temp.token = obj.text.tokenize("*");
player.chat = temp.token[0] @ "x" @ temp.token[1] @ "=" @ temp.token[0] * temp.token[1];
}


and certainly better ways if you're planning on making a calculator or so.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #14  
Old 03-20-2008, 07:19 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
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.
__________________
Do it with a DON!
Reply With Quote
  #15  
Old 03-20-2008, 10:03 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Email Google, ask for theirs, then convert it to GS2
__________________
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:48 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.