![]() |
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:
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:
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. |
Quote:
Quote:
Quote:
PHP Code:
Quote:
|
I would quite like it if you spaced the operator out a bit, i.e.
PHP Code:
PHP Code:
PHP Code:
Quote:
PHP Code:
PHP Code:
Quote:
|
Quote:
Quote:
|
Quote:
PHP Code:
PHP Code:
Quote:
|
Quote:
Quote:
|
Quote:
Quote:
|
... 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. |
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
|
Yes, he's also hot too.
|
Quote:
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. |
Quote:
|
It's as much an operator as + or - are, they are just different. Not that bad actually, maybe even useful.
|
Quote:
PHP Code:
Quote:
|
Quote:
this.text = variable SPC variable2; Which is many times more appropriate than; this.text = variable @ " " @ variable2; Thank you for your time! ;) |
Quote:
|
Quote:
|
There is also TAB. Tabs must be used when doing columns in GuiTextListCtrl or GuiMLTextCtrl.
|
| All times are GMT +2. The time now is 08:57 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.