Page 1 of 3

LinkTo()

Posted: January 20th, 2013, 10:59 pm
by ExPie
I have the following code

Code: Select all

target1 = getentarray ("target1", "targetname");	
target1_trig = getent ("target1_trig", "targetname");
target1_trig enableLinkTo();
target1_trig linkTo(target1);
But upon runing the map i get en error say that "target1_trig linkTo(target1);" is not an entity. Help?

Re: LinkTo()

Posted: January 20th, 2013, 11:58 pm
by Drofder2004
and most importantly, what IS "target1".

Re: LinkTo()

Posted: January 21st, 2013, 12:01 am
by Rezil
You can't link to an entire array of entities. If your code is correct, you can try target1_trig linkTo(target1[0]); or whichever entity you want from that array.

Re: LinkTo()

Posted: January 21st, 2013, 6:06 pm
by ExPie
Ofcourse i creatad it. And how do I know what entity of array to asign it to? Orig?

Re: LinkTo()

Posted: January 21st, 2013, 6:14 pm
by ExPie
Here is the whole code now. I'm calling it from mapname.gsc.

Code: Select all

 
main()  {
        trap1 = getentarray("trap1", "targetname");             
        trap1_trig = getent("trap1_trig", "targetname");
        button = getentarray("button", "targetname");
        get_target_trig();
        while (1)       {
                trap1_trig waittill("trigger");
                thread button();
                thread trap1();
        }
}
 
trap1() {
        trap1 movez (-640, 0.1);
        trap1 waittill ("movedone");
        player iprintlnbold("Now hit a target!");
        thread rotate_targets();
        thread targets_trig1();
        thread targets_trig2();
        thread targets_trig3();
        thread targets_trig4();
        thread targets_trig5();
}
 
button()        {
        button movez (-1, 0.5);
        button waittill ("movedone");
        button movez (1, 0.5);
}
 
 
get_target_trig()       {
        target1 = getentarray ("target1", "targetname");        
        target1_trig = getent ("target1_trig", "targetname");
        target1_trig enableLinkTo();
        target1_trig linkTo(target1[0]);
        
        target2 = getentarray ("target2", "targetname");        
        target2_trig = getent ("target2_trig", "targetname");
        target2_trig enableLinkTo();
        target2_trig linkTo(target2[0]);
 
        target3 = getentarray ("target3", "targetname");        
        target3_trig = getent ("target3_trig", "targetname");   
        target3_trig enableLinkTo();
        target3_trig linkTo(target3[0]);
 
        target4 = getentarray ("target4", "targetname");        
        target4_trig = getent ("target4_trig", "targetname");
        target4_trig enableLinkTo();
        target4_trig linkTo(target4[0]);
 
        target5 = getentarray ("target5", "targetname");        
        target5_trig = getent ("target5_trig", "targetname");
        target5_trig enableLinkTo();
        target5_trig linkTo(target5[0]);
}
 
 
rotate_targets()        {
        while(1)        {
                trap2 rotateroll ( -90, 1.2, 0.2, 0);
                trap2 waittill("rotatedone");
                wait(0.5);
                trap2 rotateroll ( 90, 1.2, 0.2, 0);
                wait(2);
                trap5 rotateroll ( -90, 1.2, 0.2, 0);
                trap5 waittill("rotatedone");
                wait(0.5);
                trap5 rotateroll ( 90, 1.2, 0.2, 0);
                wait(1);
                trap3 rotateroll ( -90, 1.2, 0.2, 0);
                trap3 waittill("rotatedone");
                wait(0.5);
                trap3 rotateroll ( 90, 1.2, 0.2, 0);
                wait(1.5);
                trap1 rotateroll ( -90, 1.2, 0.2, 0);
                trap1 waittill("rotatedone");
                wait(0.5);
                trap1 rotateroll ( 90, 1.2, 0.2, 0);
                wait(2.5);
                trap4 rotateroll ( -90, 1.2, 0.2, 0);
                trap4 waittill("rotatedone");
                wait(0.5);
                trap4 rotateroll ( 90, 1.2, 0.2, 0);
                wait(3);
        }
        
}
 
 
 
 
targets_trig1() {                               
        target1_trig waittill ("trigger");
        trap1 movez (640, 0.1);
}
 
targets_trig2() {
        target2_trig waittill ("trigger");
        trap1 movez (640, 0.1);
}
 
targets_trig3() {
        target3_trig waittill ("trigger");
        trap1 movez (640, 0.1);
}
 
targets_trig4() {
        target4_trig waittill ("trigger");
        trap1 movez (640, 0.1);
}
 
targets_trig5() {
                target5_trig waittill ("trigger");
                trap1 movez (640, 0.1);
}
 
line 7: its not an object?

Re: LinkTo()

Posted: January 21st, 2013, 6:17 pm
by Rezil
ExPie wrote:Ofcourse i creatad it. And how do I know what entity of array to asign it to? Orig?
Well what exactly are you trying to do? If you have multiple entities called "target1" it would be better to give the entity you want the trigger linked to a different targetname. If, however, "target1" is a SINGLE entity, then you need to use getEnt instead of getEntArray.

Re: LinkTo()

Posted: January 21st, 2013, 6:25 pm
by F |Madness| U
Rezil wrote:
ExPie wrote:Ofcourse i creatad it. And how do I know what entity of array to asign it to? Orig?
Well what exactly are you trying to do? If you have multiple entities called "target1" it would be better to give the entity you want the trigger linked to a different targetname. If, however, "target1" is a SINGLE entity, then you need to use getEnt instead of getEntArray.
Indeed. However he said his problem is line 7 not being an object, I assume this is

trap1_trig waittill("trigger"); where trap1_trig is not an object (eg. undefined? not familiar with CoD)

And he is using just getEnt for trap1_trig, not getEntArray. Are you sure you have given the desired object the targetname trap1_trig in radiant? Make sure you didn't accidentally typo trap_trig or something.

Re: LinkTo()

Posted: January 21st, 2013, 7:32 pm
by ExPie
I checked everyting. Every targername is correct all _trig are 1 brush and all traps are multiple brushes, each reasembeling 1 target.

Re: LinkTo()

Posted: January 21st, 2013, 7:41 pm
by ExPie
Ok, I typed tagetname instead of targetname.
Now I get an error ingame when I try to press the button. Line 26 not an entity. (button movez();)

Re: LinkTo()

Posted: January 21st, 2013, 8:24 pm
by Drofder2004
ExPie wrote:Ok, I typed tagetname instead of targetname.
Now I get an error ingame when I try to press the button. Line 26 not an entity. (button movez();)
When creating variables, you need to know about local and global. The way you are creating your variables is a local method. This means they can ONLY be used in the same function.

There are a few ways of making the entity usable in all functions.

GLOBAL (you can now use the level.button anywhere in your script)

Code: Select all

level.button = getEnt("button", "targetname"); 
thread button();
 
button()
{
   level.button movez (-1, 0.5);
   level.button waittill ("movedone");
   level.button movez (1, 0.5);
}
SELF (call the function on the entity)

Code: Select all

button = getEnt("button", "targetname");
button thread button();
 
button()
{
   self movez (-1, 0.5);
   self waittill ("movedone");
   self movez (1, 0.5);
}
PASS (pass the variable in the function)

Code: Select all

button = getEnt("button", "targetname");
thread button(button);
 
button(btn)
{
   btn movez (-1, 0.5);
   btn waittill ("movedone");
   btn movez (1, 0.5);
}

Re: LinkTo()

Posted: January 21st, 2013, 9:15 pm
by ExPie
Line 14: array is not an entity WHYY???

Code: Select all

main()  {
        level.trap1 = getentarray("trap1", "targetname");               
        level.trap1_trig = getent("trap1_trig", "targetname");
        level.button = getent("button", "targetname");
        get_target_trig();
        while (1)       {
                level.trap1_trig waittill("trigger");
                thread button();
                thread trap1();
        }
}
 
trap1() {
        level.trap1 movez (-640, 0.1);
        level.trap1 waittill ("movedone");
        player iprintlnbold("Now hit a target!");
        thread rotate_targets();
        thread targets_trig1();
        thread targets_trig2();
        thread targets_trig3();
        thread targets_trig4();
        thread targets_trig5();
}
 
button()        {
        level.button movez (-1, 0.5);
        level.button waittill ("movedone");
        level.button movez (1, 0.5);
}
 
 
get_target_trig()       {
        level.target1 = getentarray ("target1", "targetname");  
        level.target1_trig = getent ("target1_trig", "targetname");
        level.target1_trig enableLinkTo();
        level.target1_trig linkTo(level.target1[0]);
        
        level.target2 = getentarray ("target2", "targetname");  
        level.target2_trig = getent ("target2_trig", "targetname");
        level.target2_trig enableLinkTo();
        level.target2_trig linkTo(level.target2[0]);
 
        level.target3 = getentarray ("target3", "targetname");  
        level.target3_trig = getent ("target3_trig", "targetname");     
        level.target3_trig enableLinkTo();
        level.target3_trig linkTo(level.target3[0]);
 
        level.target4 = getentarray ("target4", "targetname");  
        level.target4_trig = getent ("target4_trig", "targetname");
        level.target4_trig enableLinkTo();
        level.target4_trig linkTo(level.target4[0]);
 
        level.target5 = getentarray ("target5", "targetname");  
        level.target5_trig = getent ("target5_trig", "targetname");
        level.target5_trig enableLinkTo();
        level.target5_trig linkTo(level.target5[0]);
}
 
 
rotate_targets()        {
        while(1)        {
                level.trap2 rotateroll ( -90, 1.2, 0.2, 0);
                level.trap2 waittill("rotatedone");
                wait(0.5);
                level.trap2 rotateroll ( 90, 1.2, 0.2, 0);
                wait(2);
                level.trap5 rotateroll ( -90, 1.2, 0.2, 0);
                level.trap5 waittill("rotatedone");
                wait(0.5);
                level.trap5 rotateroll ( 90, 1.2, 0.2, 0);
                wait(1);
                level.trap3 rotateroll ( -90, 1.2, 0.2, 0);
                level.trap3 waittill("rotatedone");
                wait(0.5);
                level.trap3 rotateroll ( 90, 1.2, 0.2, 0);
                wait(1.5);
                level.trap1 rotateroll ( -90, 1.2, 0.2, 0);
                level.trap1 waittill("rotatedone");
                wait(0.5);
                level.trap1 rotateroll ( 90, 1.2, 0.2, 0);
                wait(2.5);
                level.trap4 rotateroll ( -90, 1.2, 0.2, 0);
                level.trap4 waittill("rotatedone");
                wait(0.5);
                level.trap4 rotateroll ( 90, 1.2, 0.2, 0);
                wait(3);
        }
        
}
 
 
 
 
targets_trig1() {                               
        level.target1_trig waittill ("trigger");
        level.trap1 movez (640, 0.1);
}
 
targets_trig2() {
        level.target2_trig waittill ("trigger");
        level.trap1 movez (640, 0.1);
}
 
targets_trig3() {
        level.target3_trig waittill ("trigger");
        level.trap1 movez (640, 0.1);
}
 
targets_trig4() {
        level.target4_trig waittill ("trigger");
        level.trap1 movez (640, 0.1);
}
 
targets_trig5() {
        level.target5_trig waittill ("trigger");
        level.trap1 movez (640, 0.1);
}
 

Re: LinkTo()

Posted: January 21st, 2013, 9:33 pm
by Drofder2004
You need to learn the difference between Entity and Array.
An array is a GROUP of entities. An entity is a single object.

If you have ONE button (or whatever) on your map, use "getEnt" not "getEntArray".
If you have multiple buttons, then you need to use getEntArray (and also loops).

viewtopic.php?f=11&t=4011

Some scripting for dummies stuff I wrote 6+ years ago, not very nicely presented but the basics cover this.

Re: LinkTo()

Posted: January 21st, 2013, 9:37 pm
by ExPie
So if I have an array of entities I cannot move then by moving the whole array?

What is the code for moving an array of brushes?

Re: LinkTo()

Posted: January 21st, 2013, 9:48 pm
by Drofder2004
If you have an array of something, you need to run the function on every member of the array.
To do this you need loops.

Code: Select all

for( i = 0; i < level.trap1.size ; i++);
{
   level.trap1[i] movez (-640, 0.1);
}
 
   level.trap1[level.trap1.size-1] waittill("movedone");
In the above, "level.trap1" is your array. The 'for' loop creates a new local variable called 'i'.
'i' is set to the value '0' (0 is the first member of an array). Each member of the array is referred to using square brackets...
level.trap1[0], level.trap1[1], etc.

We substitute the number to the variable 'i'. When the loop repeats, the value of 'i' is increased by one (i++).
The loop stop when the value of 'i' is greater than the size of the array (level.trap1.size).

After we complete the loops, we want to tell the thread to wait until the movement is done. Instead of waiting for every movement, we just wait for the last.

The last member in an array is (level.trap1.size - 1) [you minus 1, because the array starts at 0].

Hopefully that makes sense.

Re: LinkTo()

Posted: January 21st, 2013, 10:08 pm
by ExPie
Yes it all makes perfect sense(btw I also program in c++ so I would know what loops are :D). Sry it was my fault. I thought if you have an entity of more brushes u have to use array. BUT U DONT! :D Sry. So now the code looks like this.

Code: Select all

main()	{
	level.trap1 = getent("trap1", "targetname");		
	level.trap1_trig = getent("trap1_trig", "targetname");
	level.button = getent("button", "targetname");
	get_target_trig();
	start();
}


start()	{
	level.trap1_trig waittill("trigger");
	thread button();
	thread trap1();
}


trap1()	{
	level.trap1 movez (-640, 0.1);
	level.trap1 waittill ("movedone");
	iprintlnbold("Now hit a target!");
	thread rotate_targets();
	thread targets_trig1();
	thread targets_trig2();
	thread targets_trig3();
	thread targets_trig4();
	thread targets_trig5();
}

button()	{
	level.button movez (-1, 0.5);
	level.button waittill ("movedone");
	level.button movez (1, 0.5);
}


get_target_trig()	{
	level.target1 = getent ("target1", "targetname");	
	level.target1_trig = getent ("target1_trig", "targetname");
	level.target1_trig enableLinkTo();
	level.target1_trig linkTo(level.target1);
	
	level.target2 = getent ("target2", "targetname");	
	level.target2_trig = getent ("target2_trig", "targetname");
	level.target2_trig enableLinkTo();
	level.target2_trig linkTo(level.target2);

	level.target3 = getent ("target3", "targetname");	
	level.target3_trig = getent ("target3_trig", "targetname");	
	level.target3_trig enableLinkTo();
	level.target3_trig linkTo(level.target3);

	level.target4 = getent("target4", "targetname");	
	level.target4_trig = getent ("target4_trig", "targetname");
	level.target4_trig enableLinkTo();
	level.target4_trig linkTo(level.target4);

	level.target5 = getent ("target5", "targetname");	
	level.target5_trig = getent ("target5_trig", "targetname");
	level.target5_trig enableLinkTo();
	level.target5_trig linkTo(level.target5);
}


rotate_targets()	{
	while(1)	{
		level.target2 rotatepitch ( 90, 1.2, 0.2, 0);
		level.target2 waittill("rotatedone");
		wait(0.5);
		level.target2 rotatepitch ( -90, 1.2, 0.2, 0);
		wait(2);
		level.target5 rotatepitch ( 90, 1.2, 0.2, 0);
		level.target5 waittill("rotatedone");
		wait(0.5);
		level.target5 rotatepitch ( -90, 1.2, 0.2, 0);
		wait(1);
		level.target3 rotatepitch ( 90, 1.2, 0.2, 0);
		level.target3 waittill("rotatedone");
		wait(0.5);
		level.target3 rotatepitch ( -90, 1.2, 0.2, 0);
		wait(1.5);
		level.target1 rotatepitch( 90, 1.2, 0.2, 0);
		level.target1 waittill("rotatedone");
		wait(0.5);
		level.target1 rotatepitch ( -90, 1.2, 0.2, 0);
		wait(2.5);
		level.target4 rotatepitch ( 90, 1.2, 0.2, 0);
		level.target4 waittill("rotatedone");
		wait(0.5);
		level.target4 rotatepitch ( -90, 1.2, 0.2, 0);
		wait(3);
	}
	
}




targets_trig1()	{				
	level.target1_trig waittill ("trigger");
	level.trap1 movez (640, 0.1);
	start();
}

targets_trig2()	{
	level.target2_trig waittill ("trigger");
	level.trap1 movez (640, 0.1);
	start();
}

targets_trig3()	{
	level.target3_trig waittill ("trigger");
	level.trap1 movez (640, 0.1);
	start();
}

targets_trig4()	{
	level.target4_trig waittill ("trigger");
	level.trap1 movez (640, 0.1);
	start();
}

targets_trig5()	{
	level.target5_trig waittill ("trigger");
	level.trap1 movez (640, 0.1);
	start();
}

First of all: how to get "iprintlnbold("Now hit a target!");" Showing message only to a player hitting the trigger.


Trigger on targets seems to be activating only when I throw a nade there (yes I've tried to noclip and see if it's not linked to move, but it seems it is). I have a trig damage with targername and "accumulate","2".

Somethimes the targets get bugged moving but I'll fix that on my own.