Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-08-2005, 06:59 PM
prozac424242 prozac424242 is offline
Registered User
prozac424242's Avatar
Join Date: May 2001
Location: Gone crazy: back soon
Posts: 356
prozac424242 is on a distinguished road
Send a message via ICQ to prozac424242 Send a message via AIM to prozac424242
Placing string values in your text

One thing in gs2 that I have been trying off and on how to figure out is how to put variables in strings. After seeing some random examples and taking a closer look at the gscript wiki page that I have read many times, it finally occured to me. And since for me, the solution was so elusive, I will post it here so others can see how this rather simple thing is done.

The @ symbol is what combines strings, or strings and variables, in gs2.
If you want a gui box to show the player's name at the end, you could have the text line of the GuiTextCtrl box be

PHP Code:
text "Welcome to some server that is crappy but I can't tell beacsue I am a noob with money who rented a spot and threw stuff together, "@player.nick
So: You define a string by putting it in quotes "like this"
and the player.nick is a variable whose type is a string, so it does not need quotes. The @ does not read the contents of player.nick, it simply sticks the two together.

But what if you want to put more text after the player's name?
You use another @
PHP Code:
text "Welcome to some server that is crappy but I can't tell becasue I am a noob with money who rented a spot and threw stuff together, "@player.nick@" , so have fun trying to figure out my obtuse customized player movement and swords that hit off target and graphics ripped from emulators, you know the drill.  Enjoy it while your gold account lasts casue i r b 1337 baby!"
If, instead of the player's name, you want to put in a player variable or a server string, #s(client.whateveryoucalledthestring) and #s(serverr.thestringnameyougavefortheserverstring) still works.

Also, if you have a Gui box whose text you want updated, having any kind of setTimer(number) will casue the text to flash. .05 time casues the text to not show at all, if read from a server string, if I remember correctly the server's fastest response time is .1, so in the timeout, do a check that grabs the string value to a variable, sleep for .1, and check the variable against the current string value. If the values differ, then update the text attribute of whatever you called the box. The text attribute for GuiTextCtrl ("My_Text") would be My_Text.text and you can set it equal to whatever you like in a separate part of the npc.

I hope this helps someone, and please correct me where I am wrong. But what I did here (with different text of course) works on my server.
__________________

Useful links:
Graal Stats
Client Script Functions-GS1 to GS2
Serverside Script Functions-Gscript page
Particle Engine-Player Attributes
Server Options-Admin rights-Gmaps
Quote:
Originally Posted by Admins
Thanks for developing and improving playerworlds and such
Reply With Quote
  #2  
Old 12-08-2005, 07:09 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by prozac424242
One thing in gs2 that I have been trying off and on how to figure out is how to put variables in strings. After seeing some random examples and taking a closer look at the gscript wiki page that I have read many times, it finally occured to me. And since for me, the solution was so elusive, I will post it here so others can see how this rather simple thing is done.

The @ symbol is what combines strings, or strings and variables, in gs2.
If you want a gui box to show the player's name at the end, you could have the text line of the GuiTextCtrl box be
Yes, if you would have RTFM, you would have figured this out quite quickly.

Quote:
Originally Posted by prozac424242
If, instead of the player's name, you want to put in a player variable or a server string, #s(client.whateveryoucalledthestring) and #s(serverr.thestringnameyougavefortheserverstring) still works.
Quote:
Originally Posted by Lance
4) If you do not know what you are doing, please do not post a solution here. Doing so only confounds the original advice-seeker. People who consistently post bad advice will be masked from the scripting forum.
You should NOT mix old-graalscript identifiers (#s), with the new graalscript, there is absolutely no need.
PHP Code:
text "This works: " client.stringname ", Imagine that."
Quote:
Originally Posted by prozac424242
Also, if you have a Gui box whose text you want updated, having any kind of setTimer(number) will casue the text to flash. .05 time casues the text to not show at all, if read from a server string, if I remember correctly the server's fastest response time is .1, so in the timeout, do a check that grabs the string value to a variable, sleep for .1, and check the variable against the current string value. If the values differ, then update the text attribute of whatever you called the box. The text attribute for GuiTextCtrl ("My_Text") would be My_Text.text and you can set it equal to whatever you like in a separate part of the npc.
Do NOT use Sleep() in a timeout.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #3  
Old 12-08-2005, 07:12 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
I would quite like it if you spaced the operator out a bit, i.e.
PHP Code:
res one two
Instead of...
PHP Code:
res=one@two
Note that you can also use SPC and NL operators, the former inserting a space and the latter inserting a new line (effectively, a "\n"), i.e.
PHP Code:
one "Doris";
res "Hello" SPC one
... producing "Hello Doris!".

Quote:
Originally Posted by prozac424242
If, instead of the player's name, you want to put in a player variable or a server string, #s(client.whateveryoucalledthestring) and #s(serverr.thestringnameyougavefortheserverstring) still works.
This is bad:
PHP Code:
res "My my, " #s(clientr.stringname); 
You would use the following:
PHP Code:
res "My my, " clientr.stringname
Please do not mix old gscript and gscript.

Quote:
Originally Posted by prozac424242
Also, if you have a Gui box whose text you want updated, having any kind of setTimer(number) will casue the text to flash. .05 time casues the text to not show at all, if read from a server string, if I remember correctly the server's fastest response time is .1, so in the timeout, do a check that grabs the string value to a variable, sleep for .1, and check the variable against the current string value. If the values differ, then update the text attribute of whatever you called the box. The text attribute for GuiTextCtrl ("My_Text") would be My_Text.text and you can set it equal to whatever you like in a separate part of the npc.
And if you are not updating the text every 0.1 seconds, then this is throughly bad practise and you should use approximately more events!
__________________
Skyld
Reply With Quote
  #4  
Old 12-08-2005, 07:15 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by Skyld
Note that you can also use SPC and NL operators, the former inserting a space and the latter inserting a new line (effectively, a "\n"), i.e.
PHP Code:
one "Doris";
res "Hello" SPC one
... producing "Hello Doris!".
SPC and NL look ugly


Quote:
Originally Posted by Skyld
This is bad:
PHP Code:
res "My my, " #s(clientr.stringname); 
You would use the following:
PHP Code:
res "My my, " clientr.stringname
Please do not mix old gscript and gscript.
I beat you to it >:P
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #5  
Old 12-08-2005, 07:17 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by ApothiX
SPC and NL look ugly
I am not sure about you, but I would rather do the following:
PHP Code:
this.text "Some text" NL
            
"Some more text" NL
            
"Yet another line"
... rather than:
PHP Code:
this.text "Some text\n" @
            
"Some more text\n" @
            
"Yet another line\n"
Quote:
Originally Posted by ApothiX
I beat you to it >:P
Your need for competition is bewildering.
__________________
Skyld
Reply With Quote
  #6  
Old 12-08-2005, 07:20 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by Skyld
I am not sure about you, but I would rather do the following:
PHP Code:
this.text "Some text" NL
            
"Some more text" NL
            
"Yet another line"
... rather than:
PHP Code:
this.text "Some text\n" @
            
"Some more text\n" @
            
"Yet another line\n"
Perhaps NL is good, but 'this.text = "Blah " @ variable' looks better than 'this.text = "Blah" SPC variable', IMO.

Quote:
Originally Posted by Skyld
Your need for competition is bewildering.
Stop spoiling my moments of glory.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #7  
Old 12-08-2005, 07:22 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by ApothiX
Perhaps NL is good, but 'this.text = "Blah " @ variable' looks better than 'this.text = "Blah" SPC variable', IMO.
I agree with you on the rather unnecessary use of SPC, but I suppose it falls down to preference.
Quote:
Originally Posted by ApothiX
Stop spoiling my moments of glory.
I think you have an unusual idea of glory.
__________________
Skyld
Reply With Quote
  #8  
Old 12-08-2005, 07:39 PM
prozac424242 prozac424242 is offline
Registered User
prozac424242's Avatar
Join Date: May 2001
Location: Gone crazy: back soon
Posts: 356
prozac424242 is on a distinguished road
Send a message via ICQ to prozac424242 Send a message via AIM to prozac424242
... I once again apoligize for something I posted here.
In this case, my only intent was to provide something useful.

Question : why is mixing gs1 and gs2 bad if it makes the npc work?

Also, from the first reply to my post, if you had read my post you would have seen that I DID RTFM several times already and only yesterday did this solution dawn upon me.

From the volume and content of his posts, it appears that Skyld is the most knowledgable about gs2 other than Stefan.

I vote Skyld write the gs2 version of npcprogramming.doc (in some html or php format) with such useful exaples of sample code in context. Becasue such a thing would be most helpful, as a companion to the wiki, in my opinion, which is based on my experience.

I vote for Skyld to do it becasue such an example based tutorial is something that I think many people will need, and I would write one and use it ... if it would not be so harshly criticized by apparently angry and overly critical people, such as some but not all of the poeple who post here seem to be.
And Skyld has a very good way of explaining gs2 in a way that I understand it. Thank you, Skyld.
__________________

Useful links:
Graal Stats
Client Script Functions-GS1 to GS2
Serverside Script Functions-Gscript page
Particle Engine-Player Attributes
Server Options-Admin rights-Gmaps
Quote:
Originally Posted by Admins
Thanks for developing and improving playerworlds and such
Reply With Quote
  #9  
Old 12-08-2005, 07:52 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by prozac424242
... I once again apoligize for something I posted here.
In this case, my only intent was to provide something useful.
Don't apologise for it. A significant portion of your post was useful.
Quote:
Originally Posted by prozac424242
Question : why is mixing gs1 and gs2 bad if it makes the npc work?
Because new gscript is capable of doing everything old gscript is, and in a nicer fashion.
Quote:
Originally Posted by prozac424242
From the volume and content of his posts, it appears that Skyld is the most knowledgable about gs2 other than Stefan.
I'm not too sure about that!
Quote:
Originally Posted by prozac424242
I vote Skyld write the gs2 version of npcprogramming.doc (in some html or php format) with such useful exaples of sample code in context. Becasue such a thing would be most helpful, as a companion to the wiki, in my opinion, which is based on my experience.
That's quite a large task, with quite a lot to explain, however, I may write some tutorials sometime.
Quote:
Originally Posted by prozac424242
I vote for Skyld to do it becasue such an example based tutorial is something that I think many people will need, and I would write one and use it ... if it would not be so harshly criticized by apparently angry and overly critical people, such as some but not all of the poeple who post here seem to be.
Don't take it too personally. The fact that you are trying to improve is a fairly large step forward.
Quote:
Originally Posted by prozac424242
And Skyld has a very good way of explaining gs2 in a way that I understand it. Thank you, Skyld.
You're welcome.
__________________
Skyld
Reply With Quote
  #10  
Old 12-08-2005, 08:27 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Yes, he's also hot too.
__________________
Reply With Quote
  #11  
Old 12-09-2005, 08:24 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally Posted by Skyld
I agree with you on the rather unnecessary use of SPC, but I suppose it falls down to preference.

I think you have an unusual idea of glory.
hmmm... variables that self-concatenate... yikes..... That scares me... Couldn't stefan had just recommended defining your own variables and going

SPC = " ";
NL = "\n";
function(string@SPC@string@NL@string);

I generally would do the above only if I'm lazy though, otherwise I'd write in the space and the new line myself. I can see how SPC can be really really useful when trying to debug something in a hurry using the NPC's chat string.
Reply With Quote
  #12  
Old 12-09-2005, 09:57 AM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by jake13jake
hmmm... variables that self-concatenate... yikes..... That scares me... Couldn't stefan had just recommended defining your own variables and going

SPC = " ";
NL = "\n";
function(string@SPC@string@NL@string);

I generally would do the above only if I'm lazy though, otherwise I'd write in the space and the new line myself. I can see how SPC can be really really useful when trying to debug something in a hurry using the NPC's chat string.
Well, they're not really variables.
__________________
Skyld
Reply With Quote
  #13  
Old 12-09-2005, 03:59 PM
Fry Fry is offline
Registered User
Fry's Avatar
Join Date: Sep 2001
Location: Germany
Posts: 384
Fry has a spectacular aura about
It's as much an operator as + or - are, they are just different. Not that bad actually, maybe even useful.
__________________
Graal Statistics

Top 3 servers at the moment (players):


Reply With Quote
  #14  
Old 12-09-2005, 06:10 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by jake13jake
hmmm... variables that self-concatenate... yikes..... That scares me... Couldn't stefan had just recommended defining your own variables and going

SPC = " ";
NL = "\n";
Actually, they are comparible to a C's #define directive,
PHP Code:
#define SPC @ " " @
#define NL @ "\n" @ 
Quote:
Originally Posted by jake13jake
function(string@SPC@string@NL@string);
That's even more ugly than what it really is.. 'function(string SPC string NL string);'
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #15  
Old 12-09-2005, 09:46 PM
Dach Dach is offline
call me Chad, it's cooler
Dach's Avatar
Join Date: Aug 2002
Posts: 1,899
Dach is on a distinguished road
Quote:
Originally Posted by ApothiX
Perhaps NL is good, but 'this.text = "Blah " @ variable' looks better than 'this.text = "Blah" SPC variable', IMO.
The more applicaple usage of SPC is;
this.text = variable SPC variable2;
Which is many times more appropriate than;
this.text = variable @ " " @ variable2;

Thank you for your time!
__________________
Scripting Documents:Old Script Documentation-Movement Tutorial

Last edited by Dach; 12-09-2005 at 09:48 PM.. Reason: SHUTUP
Reply With Quote
Reply


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 10:32 AM.


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