access element of a vector
by Brian Carlson · in Torque 2D Beginner · 03/27/2016 (12:53 pm) · 4 replies
Hello everyone,
I've been having trouble with vectors for a while now, and haven't found what I want from the TorqueScript guides.
For example, if I have
This would be useful to get the position of some sprite on the screen.
To get around this, to access a sprite's x and y position, I have had declare the x and y positions first, using them to make the position.
It would be nice to be able to access the %inn.Position variable directly.
Thanks in advance!
Brian Carlson
I've been having trouble with vectors for a while now, and haven't found what I want from the TorqueScript guides.
For example, if I have
%inn.Position = "20 10";I haven't been successful at using
%inn.getX = %inn.Position[0]; %inn.getY = %inn.Position[1];
This would be useful to get the position of some sprite on the screen.
To get around this, to access a sprite's x and y position, I have had declare the x and y positions first, using them to make the position.
%inn.PosX = 20; %inn.PosY = 10; %inn.Position = %inn.PosX SPC %inn.PosY;...later
%otherSprite.Position = (%inn.PosX - 2) SPC (%inn.PosX + 10);
It would be nice to be able to access the %inn.Position variable directly.
Thanks in advance!
Brian Carlson
#2
03/27/2016 (4:50 pm)
Great! Thank you! That's a big help
#3
03/27/2016 (6:38 pm)
Not to mention:%spaceSeparated = "10 20"; %first = getWord(%spaceSeparated, 0); %second = getWord(%spaceSeparated, 1); // tab or newline separated %tabSeparated = "10" TAB "20"; // because tabs don't work in the forum editor %first = getField(%tabSeparated, 0); %second = getField(%tabSeparated, 1); // newline separated %newlineSeparated = "10" NL "20"; // for obvious reasons %first = getRecord(%newlineSeparated, 0); %second = getRecord(%newlineSeparated, 1);
#4
03/28/2016 (5:50 am)
Thank you, Richard. Those are also great to know!
Torque Owner Nathan Martin
TRON 2001 Network
String Accessors
You can now access a string using:
So in your example you could do: