Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Scripting questions (https://forums.graalonline.com/forums/showthread.php?t=134268910)

Torankusu 02-03-2014 05:22 PM

For what its worth, params start at 0

Your npc script:
params[0] = buymenu1
params[1] = 1000
params[2] = nameyouhad?

Also, you can do:
onActionClientside (cmd, price, itemname)
and reference the parameters passed from serverside that way.

Ex: echo(price);

iDigzy 02-05-2014 06:22 AM

Quote:

Originally Posted by Torankusu (Post 1725855)
For what its worth, params start at 0

Your npc script:
params[0] = buymenu1
params[1] = 1000
params[2] = nameyouhad?

Also, you can do:
onActionClientside (cmd, price, itemname)
and reference the parameters passed from serverside that way.

Ex: echo(price);

Ahh, thanks for the reply anyways :).

Would anyone be able to explain tokenizing to me/link me to anything on it please?

Torankusu 02-05-2014 11:45 AM

Quote:

Originally Posted by iDigzy (Post 1725894)
Ahh, thanks for the reply anyways :).

Would anyone be able to explain tokenizing to me/link me to anything on it please?

obj.tokenize([delimiters]) - splits the string into an array wherever the delimiters occur

Example:
Player chats: "This is an example"

PHP Code:

player.chat.tokenize(" "); //uses spaces as separator 

Can access tokens like this:
tokenscount (will yield 4)
tokens[0] will reference the first token (the word "this").
Similarly,
tokens[2] will reference the word "an".

callimuc 02-05-2014 10:47 PM

Quote:

Originally Posted by Torankusu (Post 1725902)
obj.tokenize([delimiters]) - splits the string into an array wherever the delimiters occur

Example:
Player chats: "This is an example"

PHP Code:

player.chat.tokenize(" "); //uses spaces as separator 

Can access tokens like this:
tokenscount (will yield 4)
tokens[0] will reference the first token (the word "this").
Similarly,
tokens[2] will reference the word "an".

ps: if its only for spaces, you could also just do player.chat.tokenize()

iDigzy 02-05-2014 11:51 PM

Quote:

Originally Posted by Torankusu (Post 1725902)
obj.tokenize([delimiters]) - splits the string into an array wherever the delimiters occur

Example:
Player chats: "This is an example"

PHP Code:

player.chat.tokenize(" "); //uses spaces as separator 

Can access tokens like this:
tokenscount (will yield 4)
tokens[0] will reference the first token (the word "this").
Similarly,
tokens[2] will reference the word "an".

Thanks :), would you use tokenizeing as well when doing such scripts as
PHP Code:

if (player.chat.starts("text")){ 
player.chat.substring;


?
Also, for the delimiters, you would basically be able to put for example a word such as "idigzy" and wherever that word occurs it splits it :o?

Torankusu 02-06-2014 12:31 AM

Quote:

Originally Posted by iDigzy (Post 1725921)
Thanks :), would you use tokenizeing as well when doing such scripts as
PHP Code:

if (player.chat.starts("text")){ 
player.chat.substring;



Your example isn't a proper use of substring ( string.substring(index[,length]) ) , but, essentially, yes, you could tokenize the player's chat if a condition is met. I'll let someone else fill you in on substring as I know how it works (sometimes), but am not familiar enough to verse you on its uses...sorry...


random tailor example for tokenize [better ways to do this...example for simplicity sake..]:
PHP Code:

if (player.chat.starts("/set ")){ //player says "/set shoes"
  
player.chat.tokenize(); //as previously mentioned, SPACES become separators
  
if (tokens[1] == "shoes"){
    
player.colors[2] = tokens[2];
    
//OR...
    //player.colors[2] = player.chat.substring(10,-1); // not 100% sure on this??
  
}


Quote:

Also, for the delimiters, you would basically be able to put for example a word such as "idigzy" and wherever that word occurs it splits it :o?
yeah, you get the concept....
some common delimiters: are , (commas), spaces . (periods) , and so on...

there is a tokenize2 but I didn't want to include it.
You can scripthelp it.

Is there anything you are trying to do in specific, there might be a better approach?

iDigzy 02-06-2014 01:37 AM

@Torankusu Thanks for all the help on that :). I'm not really trying to do anything in particular at the moment, I just thought I'd play around with it since I may use it in the future.

sssssssssss 02-06-2014 03:16 AM

PHP Code:

str.substring(start[,length]) - extracts a substring out of str 

the second parameter is how long you want to grab for the substring. -1 for the length will go to the end of the string.

Also
PHP Code:

function ChatBar.onAction() 

is the same as
PHP Code:

function onPlayerChats() 

From what I understand it's recommended to use ChatBar. I've even had issues with playerchats here and there, but not with chatbar. ChatBar is the Gui default where you type in the text.

and
PHP Code:

ChatBar.text 

is the same as
PHP Code:

player.chat 

when using the ChatBar function instead.

so:
PHP Code:

function ChatBar.onAction() {
  if (
ChatBar.substring(04) == "/set") { //honestly i cant remember if it starts at 0 or 1, I believe its 0. If not, you'd do 1, 4
    
temp.tokens ChatBar.text.tokenize(); //as previously mentioned, SPACES become separators
  
if (tokens[1] == "shoes"){
    
player.colors[2] = tokens[2];
  }
}
// i believe you could dynamically set it with substrings, but since it's already in tokens, it's better to just use the tokens. 


iDigzy 02-07-2014 07:23 PM

@sssssssssss thanks for the response :)

sssssssssss 02-08-2014 12:34 AM

I saw an error in my code. :x sry

PHP Code:

function ChatBar.onAction() {
  if (
ChatBar.text.substring(04) == "/set") { //honestly i cant remember if it starts at 0 or 1, I believe its 0. If not, you'd do 1, 4
    
temp.tokens ChatBar.text.tokenize(); //as previously mentioned, SPACES become separators
  
if (tokens[1] == "shoes"){
    
player.colors[2] = tokens[2];
  }
}
// i believe you could dynamically set it with substrings, but since it's already in tokens, it's better to just use the tokens. 


iDigzy 02-09-2014 04:12 PM

Would anyone be able to link me to some guides on databases/some good examples :)?

cyan3 02-09-2014 06:48 PM

Quote:

Originally Posted by iDigzy (Post 1725994)
Would anyone be able to link me to some guides on databases/some good examples :)?

The Graal wiki has a good page on the use of SQLite in GScript.

http://wiki.graal.net/index.php/Crea...t/Using_SQLite

cbk1994 02-09-2014 09:28 PM

Quote:

Originally Posted by cyan3 (Post 1725998)
The Graal wiki has a good page on the use of SQLite in GScript.

http://wiki.graal.net/index.php/Crea...t/Using_SQLite

I wouldn't really call it a good page. A lot of the explanation is not very clear and I didn't have a very good understanding of SQLite when I wrote it.

My advice would probably be to learn SQL/SQLite outside of Graal first. Using it in Graal will then be pretty easy.

callimuc 02-10-2014 10:11 PM

Quote:

Originally Posted by sssssssssss (Post 1725963)
I saw an error in my code. :x sry

PHP Code:

function ChatBar.onAction() {
  if (
ChatBar.text.substring(04) == "/set") { //honestly i cant remember if it starts at 0 or 1, I believe its 0. If not, you'd do 1, 4
    
temp.tokens ChatBar.text.tokenize(); //as previously mentioned, SPACES become separators
  
if (tokens[1] == "shoes"){
    
player.colors[2] = tokens[2];
  }
}
// i believe you could dynamically set it with substrings, but since it's already in tokens, it's better to just use the tokens. 


now if there isnt some kind of error then ill restart scripting and learn it all from the beginning :p

sssssssssss 02-11-2014 01:49 PM

:x


All times are GMT +2. The time now is 07:37 PM.

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