getWord.word
by rennie moffat · in Torque Game Builder · 08/06/2009 (1:25 pm) · 17 replies
I am trying to understand the purpose of the getWord method.
About the author
My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.
#2
Example:
08/06/2009 (1:52 pm)
The getWord method will return a set of characters (a word) that is part of a string, separated by spaces:Example:
%test = "I hope this helps"; echo(getWord(%test, 0); //this will output 'I' echo(getWord(%test, 1); //this will output 'hope' echo(getWord(%test, 2); //this will output 'this' echo(getWord(%test, 3); //this will output 'helps'
#4
08/06/2009 (2:20 pm)
but so how would "getting a word" relate to this function?function player::move(%this, %direction)
{
%currentTile = movementLayer.pickTile(%this.getPosition());
%nextTile = %currentTile;
%x = getWord(%currentTile, 0);
%y = getWord(%currentTile, 1);
#5
08/06/2009 (2:30 pm)
%currentTile is going to be set to a value like "55 23". So the getWord call would set %x to 55 and %y to 23.
#6
08/06/2009 (2:37 pm)
so is getWord here simply separating the x and y from currentTile which contains both?
#7
Think of getWord as:
getWord(string to read, number of word to return)
So in your example:
Which shows us that %currentTile is a string (sentence) with 2 words, "55" and "23" (TGB uses a space to seperate the words in a string)
Now you pass the word number you want to see in the "number of word to return" parameter, however do note the first word is 0, the second word is 1 and so on.
So if you wanted to see the X postion of your %currentTile you would use:
Which translates to get the first word from the string %currentTile.
To get the Y position you'd use:
Hope this helps, i'm gone off on one a bit i think!
Cheers
Colin
08/06/2009 (2:53 pm)
Rennie,Think of getWord as:
getWord(string to read, number of word to return)
So in your example:
%currentTile = "55 23"
Which shows us that %currentTile is a string (sentence) with 2 words, "55" and "23" (TGB uses a space to seperate the words in a string)
Now you pass the word number you want to see in the "number of word to return" parameter, however do note the first word is 0, the second word is 1 and so on.
So if you wanted to see the X postion of your %currentTile you would use:
%x = getWord(%currentTile, 0);
Which translates to get the first word from the string %currentTile.
To get the Y position you'd use:
%y = getWord(%currentTile, 1);which again means get the second word from the same string.
Hope this helps, i'm gone off on one a bit i think!
Cheers
Colin
#8
So You have to excuse me but I am just learning and am a relativley minor programmer, (could you tell) but can I think of a string as a sentence per say where I am linking multiple "things" in order to create a "thought"?
OR...a string is a statment/variable(not sure of term) in this case %currentTile.
Where %currentTile has a few "factors" (x, y). the x and y make up the words of the string?
If so, does a string require an "=" between the main variable/statement, as in this example? or can a string be defined by many things I see.
onMouseDown(%this, worldPos)
?
08/06/2009 (3:01 pm)
ok this is helpful.So You have to excuse me but I am just learning and am a relativley minor programmer, (could you tell) but can I think of a string as a sentence per say where I am linking multiple "things" in order to create a "thought"?
OR...a string is a statment/variable(not sure of term) in this case %currentTile.
Where %currentTile has a few "factors" (x, y). the x and y make up the words of the string?
If so, does a string require an "=" between the main variable/statement, as in this example? or can a string be defined by many things I see.
onMouseDown(%this, worldPos)
?
#9
while it may be unessacary I just want this clear in my head. here, the getWord is calling the worldPos x and y and passing it onto the moveTo command.
:is this correct?
09/11/2009 (12:44 pm)
function sceneWindow2D::onMouseUp(%this, %worldPos, %clicks, %modifier)
{
%targetX = getWord(worldPos, 0);
%targetY = getWord(worldPos, 1);
$cube.moveTo(%targetX, %targetY, true, false, true, 0.1);
}while it may be unessacary I just want this clear in my head. here, the getWord is calling the worldPos x and y and passing it onto the moveTo command.
:is this correct?
#10
Is obtaining the first series of characters before the first space -- 22 and setting it to the local variable %targetX. The 2nd line does the same thing, using index 1 -- returning 33 (above example).
Your third line would look like
where "22" and "33" are the values for the variables
09/11/2009 (6:18 pm)
In your above example, wordPos is a string that returns "22 33" as an example.%targetX = getWord(%worldPos, 0);
Is obtaining the first series of characters before the first space -- 22 and setting it to the local variable %targetX. The 2nd line does the same thing, using index 1 -- returning 33 (above example).
Your third line would look like
$cube.moveTo("22", "33",...)where "22" and "33" are the values for the variables
#11
Hi I was just looking thru this code, it is the world limit setting of the fish behavior and relates to the getWord process.
If you see, the getWord, as it relates to world limits are 1 thru 4,
however I would have thought 0-3. Am I right? Am I missing something?
Thanks.
10/22/2009 (12:08 pm)
%limit0 = getWord(%worldLimit, 1);
%limit1 = getWord(%worldLimit, 2);
%limit2 = getWord(%worldLimit, 3);
%limit3 = getWord(%worldLimit, 4);
%this.setWorldLimit("NULL", %limit0, %limit1, %limit2, %limit3 , true);Hi I was just looking thru this code, it is the world limit setting of the fish behavior and relates to the getWord process.
If you see, the getWord, as it relates to world limits are 1 thru 4,
however I would have thought 0-3. Am I right? Am I missing something?
Thanks.
#12
the getWord command starts from zero to whatever number of words are in the input string.
PS: b4 i forget, you can always check the docs .... if im not mistaken, while this has been talked a lot in the forums, the command is well explained in the documentation that comes with the engine and in the TGB network.
cheers.
10/22/2009 (12:43 pm)
nope. for the very 1st time in ages, you got it right. the getWord command starts from zero to whatever number of words are in the input string.
PS: b4 i forget, you can always check the docs .... if im not mistaken, while this has been talked a lot in the forums, the command is well explained in the documentation that comes with the engine and in the TGB network.
cheers.
#13
thanks dude.
Just to be sure tho, For instance in WorldLimit... actually this is where I was going wrong. I forgot about the first variable, %Mode(0), thats why minX, Y etc begin at one. My bad, thanks!
10/22/2009 (12:52 pm)
Great, thanks dude.
Just to be sure tho, For instance in WorldLimit... actually this is where I was going wrong. I forgot about the first variable, %Mode(0), thats why minX, Y etc begin at one. My bad, thanks!
#14
cheers.
10/22/2009 (1:06 pm)
cool... sometimes, when you read the docs, you can find so many useful info, that you'll be amazed that if you read them, ad experiment some, you wont have to actually ask for basic things in a forum meant to solve real problems.cheers.
#15
Not to mention waste my time typing a meaningless response,
Cheers!
10/22/2009 (1:07 pm)
I agree that is what I have been doing. So in the future please do not assume what I am doing. By assuming (which you do) you make an ass out of me and you.Not to mention waste my time typing a meaningless response,
Cheers!
#16
10/22/2009 (1:26 pm)
k ... i wont assume if you dont open more useless threads... deal?
Torque Owner rennie moffat
Renman3000