Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   tokenize weapon name (https://forums.graalonline.com/forums/showthread.php?t=134259817)

sssssssssss 07-13-2010 08:05 AM

tokenize weapon name
 
if have something like
PHP Code:

for (weps : player.weapons) 

going on and adding each to an array after meeting certain conditions, but when showing the weapon name i would want to cut out anthing before a "/".

Ex: "Staff/Tool"; I would only want it to show "Tool". I know its probably tokenize but dont know how to do that with something like a weapon name.

Switch 07-13-2010 09:00 AM

PHP Code:

weps.tokenize("/"); 

Will tokenize everything between /'s.

PHP Code:

weps.tokenize("/')[1]; 

In your example, would return "Tool".

PHP Code:

temp.weps = "Gun/SMG/P90";
temp.weps.tokenize("/")[1]; 

Would return "SMG".

sssssssssss 07-13-2010 03:53 PM

Ah ok thanks switch!

cbk1994 07-13-2010 04:16 PM

Quote:

Originally Posted by Switch (Post 1587339)
PHP Code:

weps.tokenize("/"); 

Will tokenize everything between /'s.

No, no, no!

'weps' in the weapon object, not the name of the weapon.

If you want the last part:
PHP Code:

for (temp.weps : player.weapons) {
  
temp.tokens = weps.name.tokenize("/");
  
temp.realName = tokens[tokens.size() - 1];
} 

You also might want to name the temporary weapon object 'wep' instead of 'weps' as the latter indicates that it is a list of weapons rather than a single weapon.

Switch 07-15-2010 09:27 AM

Quote:

Originally Posted by cbk1994 (Post 1587394)
'weps' in the weapon object, not the name of the weapon.

Wasn't even aware of that, I thought player.weapons gave an array of strings.

Quote:

Originally Posted by Switch (Post 1587339)
PHP Code:

weps.tokenize("/')[1]; 


LOL@mistake

sssssssssss 07-15-2010 11:52 PM

Either way actually worked, but chris' way gives the last bit no matter what.

cbk1994 07-16-2010 12:11 AM

Quote:

Originally Posted by sssssssssss (Post 1587835)
Either way actually worked, but chris' way gives the last bit no matter what.

Just because it worked does not make it correct :). Hopefully in the future Stefan will fix such errors from working in the first place.


All times are GMT +2. The time now is 05:55 AM.

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