Game Development Community

Lists

by Gavin Beard · in Torque Game Builder · 03/17/2005 (2:53 pm) · 14 replies

Hey ya all, ok so here it is, i'm working on my mini turn based strat. before trying a mini rts. So far it bad's in the lead unit for the main player, assigns them a position and adds a cursor to the screen whic is a box that highlights the selected sprite or tile. fine works a treat. no what i want to do is add in the the 'start troops' which is will 4 units all positioned somewhere around the lead player. is there some kinda 'linked list' i should use to create the armies, or is it one of the 'sim objects' i read about somewhere, or do i just keep creating the units using a similar function to when i add the lead player and add some custom field to say what team they r on??

i guess i need to be able to delete the unit once it has been destroyed in it's turn based glory of a battle :)

all feed back welcome as always,

fyi. looking in the basic tutorial it seems to just keep calling the createenemy function to add new baddies, but doesnt seem to have n e way of adding a fustom variable to let me know what team they r on, so i guess thats not the way forward. also when trying this myself, all the units seem to have the same ID number so atm i use mounting to center the cursor on the unit, when i go to pick the second object my console tells me it's alreay mounted and the cursor stays put :'(

#1
03/17/2005 (6:21 pm)
Torquescript supports dynamic properties for most (all?) objects.

Just do this:

%myobject.enemyteam=1; // or "BADDIES" or whatever...

Or you could use T2D's groups if you like.
#2
03/17/2005 (11:55 pm)
Thats cool, should help alot, my main concearn is how to create a new unit as and when needed, as i said i dont want to keep calling the function that i use to make my main unit as all units end up with the same ID and i can only mount one unit then
#3
03/18/2005 (12:18 am)
Well i guess it does work calling createplayer function each time, but when mounting the cursor to a diff. unit i need to call dismount() first, lol :)

I was looking in the console and thinging the id it was giving me with the 'all ready mounted' error was to do with the units, but it was the cursor id.

So i guess we move on, i am now working on a way of creating diff. units i guess this is just a case of adding some var's to the function call and using some if or case statements to determine the units created,

i think i will work on the movement last as i need to work out how far players can move a displaying some kinda grid around the unit to let the player know where they can move. So sorry for all the stupid questions but i'm sure there will be a few more!!!
#4
03/18/2005 (12:34 am)
Gavin,

I removed the error-message for mounting when already mounted. I simply dismount now.

You can change this code yourself in "fxSceneObject2D.cc" (approx line 2260) from ...
// Check if we're already mounted.
if ( processIsMounted() )
{
	Con::warnf("fxSceneObject2D::mount - Object '%s' is already mounted!", getIdString());
	return -1;
}
... to ...
// Are we already mounted?
if ( processIsMounted() )
	// Yes, so dismount.
	dismount();

Do a recompile and it will automatically dismount for you. Expect this behaviour change in the next update.

Hope this helps,

- Melv.
#5
03/18/2005 (1:18 am)
Sure does thx, it wasnt a major issue coz i called dismount before mount n e way, but this saves me having to remember to do that in future
#6
03/18/2005 (6:20 am)
Ok, another slight prob.
i have use setname() to give my tilemap a name so when i'm picking units and mounting them i dont mount the tile map by mistake. so i use setname and give the tile layer 0 a name of "base" now in the onmousedown even if i just stick %obj = getWord( %pickList, 0); and click a unit i get nothing, if i click n e where on the map i get 'base' displayed in console, great. if i use an if statement:

%obj = getWord( %pickList, 0);
echo(%obj.getname());
if (%obj.getname() = "base")
{
echo("hit");
}
i get base displayed if i click a area of map, bu the if statement doesnt follow through and stick 'hit' in the console. n e ideas why :D
#7
03/18/2005 (6:39 am)
The string equality operator is different than the one for everything else. (this got me at first too)

To compare strings:
if (%obj.getname() $= "base")

Remember that "=" isn't correct to compare other types either. For that you need to use "==". "=" is the assignment operator.
#8
03/18/2005 (6:43 am)
Oh, and you might want to read the torquescript docs.

www.garagegames.com/docs/torque/general/pt03.html

Alas, T2D owners don't have access to some important parts of this, like the operator list. (Melv/Josh, any update on getting this fixed?)

Here's a list of operators I found in another document:

Assignment operators
= Assigns the value of the second operand to the first operand.

Mathematical Operators:
+ (Addition) Adds 2 numbers
- (subtraction) Subtracts the value of its argument.
* (Multiplication) Multiplies 2 numbers.
/ (Division) Divides 2 numbers.
% (Modulus) Computes the integer remainder of dividing 2 numbers.
+= Adds 2 numbers and assigns the result to the first.
-= Subtracts 2 numbers and assigns the result to the first.
*= Multiplies 2 numbers and assigns the result to the first.
/= Divides 2 numbers and assigns the result to the first.
%= Computes the modulus of 2 numbers and assigns the result to the first.
++ (Increment) Adds one to a variable representing a number (returning either the new or old value of the variable)
-- (Decrement) Subtracts one from a variable representing a number (returning either the new or old value of the variable)

Bitwise Operators:
~ (Bitwise NOT) Flips the bits of its operand.
| (Bitwise OR) Returns a one in a bit if bits of either operand is one.
& (Bitwise AND) Returns a one in each bit position if bits of both operands are ones.
^ (Bitwise XOR) Returns a one in a bit position if bits of one but not both operands are one.
<< (Left shift) Shifts its first operand in binary representation the number of bits to the left specified in the second operand, shifting in zeros from the right.
>> (Sign-propagating right shift) Shifts the first operand in binary representation the number of bits to the right specified in the second operand, discarding bits shifted off.
|= Performs a bitwise OR and assigns the result to the first operand.
&= Performs a bitwise AND and assigns the result to the first operand.
^= Performs a bitwise XOR and assigns the result to the first operand.
<<= Performs a left shift and assigns the result to the first operand.
>>= Performs a sign-propagating right shift and assigns the result to the first operand.

String operators::
@ Concatenates one or more values together to form a new value
NL Concatenates one value together with a new line to form a new value
TAB Concatenates one value together with a tab to form a new value
SPC Concatenates one value together with a space to form a new value

Logical Operators:
! evaluates the opposite of the value specified
&& requires both values to be true for the result to be true.
|| requires only one value to be true for the result to be true.

Relational Operators:
== value1 and value2 are equal
!= value1 and value2 are not equal
< value1 is less than value2
> value1 is greater than value2
<= value1 is less than or equal to value2
>= value1 is greater than or equal to value2

String comparison Operators:
$= string1 is equal to string2
!$= string1 is not equal to string2
#9
03/18/2005 (6:59 am)
Thanks alot, i own torque but got it as summin to lear later so didnt know of this resource, thats exactly what i was after and works a treat, now only units can be selected :) something similar (i.e tagging a name) to a each tile would be nice as i think the only way to know what building i have selected is to create a txt file with symbols that relate to the corresponding tile, read the txt file into a 2d array at load time and use that to test what type of tile the unit is currently on.
#10
03/18/2005 (7:01 am)
Check the reference documentation for T2d under fxtilemap2d.
You'll find a handy setCustomData method. (or something close, I don't have it in front of me.)
#11
03/18/2005 (7:03 am)
Nah thats cool, thatnks for the point.

*alt tab's to ref. doc's
#12
03/18/2005 (7:25 am)
And just for my info, does the tile x/y need to be logical x.y or the world coords? i.e woul x = 10 and y = 10 be 10 tiles across by 10 tiles down or would it be the tile at world pos. 10,10

*edit: thought i'd just point out i did look in the docs but cant see a ref. to it
#13
03/18/2005 (7:48 am)
I'm not really sure what you're asking.

Are you asking what to pass SetTileCustomData? If so, the X/Y is the tile you want, not the world coords.
#14
03/18/2005 (8:17 am)
Well, thats just what i was askin