Array help
Moderator: Core Staff
Array help
So I recently started working with arrays and I have a question about them.
How do I get trigger 1 to open door 1 with out having to put the numbers in?
Any help would be appreciated.
How do I get trigger 1 to open door 1 with out having to put the numbers in?
Any help would be appreciated.
Re: Array help
say u have 10 triggers and 10 doors named respectively - so trig1 is to open door1, trig2 is to open door2 and so on.
the code below lets the ten triggers open the corresponding doors (in the example, the doors move upstairs)
the code below lets the ten triggers open the corresponding doors (in the example, the doors move upstairs)
Code: Select all
main()
{
for (i = 1; i < 11; i++)
thread openMe(i);
}
openMe(i)
{
door = getEnt("door"+i, "targetname");
trig = getEnt("trig"+i, "targetname");
while (1)
{
trig waittill("trigger");
door moveZ(100, 1);
}
}
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
Re: Array help
Thats not an array, thats just scripting.
You can do the following.
Make your doors.
Give them a targetname of simply "door".
Now make your triggers.
(Do not give them a targetname)
Next select your first door, then select your first trigger and press W to link them.
Do this for all combinations, making sure to select the DOOR first.
Now
The only problem with this code is making the door rotate in the correct direction.
There are several ways you can do this...
1. Make sure all doors and hinges are in the same place, so that rotating 90 degrees will always work.
2. Make different arrays for doors that rotate different directions
3. Use the script_noteworthy attribute to assign the doors a value to which you can recall in the scripts, and then coding an "if" or "switch" statement...
4. Using a script origin linked to the door and scripting the door to move to the origin and back...
You can do the following.
Make your doors.
Give them a targetname of simply "door".
Now make your triggers.
(Do not give them a targetname)
Next select your first door, then select your first trigger and press W to link them.
Do this for all combinations, making sure to select the DOOR first.
Now
Code: Select all
main()
{
doors = getentarray("door", "targetname");
for(i=0li<doors.size;i++)
doors[i] thread doorThink();
}
doorThink()
{
trig = self.target;
while(1)
{
trig waittill("trigger");
// Start opening door etc
}
}
There are several ways you can do this...
1. Make sure all doors and hinges are in the same place, so that rotating 90 degrees will always work.
2. Make different arrays for doors that rotate different directions
3. Use the script_noteworthy attribute to assign the doors a value to which you can recall in the scripts, and then coding an "if" or "switch" statement...
4. Using a script origin linked to the door and scripting the door to move to the origin and back...
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010
Re: Array help
in fact, is there a difference between these ways (in-game)?
Re: Array help
brushmodels have their own set of angles, so rotating should work. u can change their angles so that they fit to the necessary direction.
example:
key: angles
value: 0 90 0
example:
key: angles
value: 0 90 0
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
Re: Array help
Yes, the use of an array gives you more options if you wish to expand on the idea.megazor wrote:in fact, is there a difference between these ways (in-game)?
Although this is true, you do not always wish to rotate the door clockwise, so the doors that you wish to open anti-clockwise, you would need to change the code.megazor wrote:brushmodels have their own set of angles, so rotating should work. u can change their angles so that they fit to the necessary direction.
example:
key: angles
value: 0 90 0
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010
Re: Array help
I'll have to try that, thanks.
Re: Array help
for example:gives you more options
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
Re: Array help
array.size = No need for me to count my entities.megazor wrote:for example:gives you more options
Prefab = No need for me to name every individual script object in the map, I also do not need to worry about how many I use.
Reduced human error = What happens when you accidently skip a number while making the 34th door on your map?
Go create a map with 50 doors and 50 triggers and I will do the same, see who finishes first?
- You make 100 different individual entities
- I make 1 entity and link the trigger, prefab, copy and paste 50 times.
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010
Re: Array help
well the things u enumerated sound nice but they arent 'options', they just save time of a mapper. what i meant was some advantage in-game.
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
Re: Array help
An array is just an easy accesible list, in this case of entities.
Consider it a group I can easily move around.
It makes scripting life easier, as I only have to write ONE line of code to get the array, and not create a loop to define the array. Once the array has been created I can easily and uniformly use the array using a SINGLE varaible, I can assign a variable to a global variable and not require multiple threads when obtaining a single unit from the array.
I can always reference the count of arrays array[array.size-1] will always reference the last entry.
When assigning array contents I can dynamically change the contents without changing the varialbe being used...
Are you just trolling now, or are you seriously not taking the fact that arrays are better than looping threads?
Consider it a group I can easily move around.
It makes scripting life easier, as I only have to write ONE line of code to get the array, and not create a loop to define the array. Once the array has been created I can easily and uniformly use the array using a SINGLE varaible, I can assign a variable to a global variable and not require multiple threads when obtaining a single unit from the array.
I can always reference the count of arrays array[array.size-1] will always reference the last entry.
When assigning array contents I can dynamically change the contents without changing the varialbe being used...
Are you just trolling now, or are you seriously not taking the fact that arrays are better than looping threads?
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010
Re: Array help
u wrote almost the same. u just should have said there was no difference in-game. thats what i was wondering of. lol.
and btw, i may be blind but ur code loops threads as well as mine does.
and btw, i may be blind but ur code loops threads as well as mine does.
-
- Core Staff
- Posts: 2214
- Joined: February 6th, 2006, 3:18 pm
- Location: Germany/Bayern
Re: Array help
Don't forget that you are supposed to write some nice and clear code that is reusable.
THAT HANDS WERE NOT TRACED!
visit my blog: Link
visit my blog: Link
Soviet wrote:Yeah, watch out, Peds will hit you with his +5 D-Battleaxe of homosexuality
Re: Array help
Well I probably screwed it up, but capital W turned on show entities as wireframe and w didn’t say that it did anything. Still tried the script out and it didn’t work.
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
Re: Array help
Post your script in full.
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010
Who is online
Users browsing this forum: No registered users and 4 guests