UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

Scripting Questions

broken avatar :(
Created 10 years ago
by Scobalula
0 Members and 1 Guest are viewing this topic.
2,307 views
broken avatar :(
×
broken avatar :(
OnionmanVere Bo21
Location: ieu dnt wnt 2 no
Date Registered: 27 September 2013
Last active: 7 days ago
Posts
1,864
Respect
Forum Rank
Zombie Destroyer
Primary Group
Community Mapper
My Groups
More
Personal Quote
ok
Signature
Aye mate you don't know me so y don't you shut tf up ok buddy :)

×
Scobalula's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Box Mappers Elite
Box Mappers Elite
Community Mapper Has released one or more maps to the UGX-Mods community which have been added to the UGX Map Manager.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Scobalula's Contact & Social Links
So I have been learning a lot about GSC and scripting as of late, but there's some things I can't get my head around when it comes to arrays (and maybe other things that may relate to it).

Let me take this piece of code as an example that Hitman done for my wall weapon light fx and break down what's confusing me:

Code Snippet
Plaintext
bo2_weapon_light()
{
fx_1 = GetEntArray("weapon_upgrade","targetname");

wait 1;
for(i=0;i<fx_1.size;i++)
playFx(level._effect["wall_weapon_light"], fx_1[i].origin);
}

The first part I understand, getting the array of entities, etc. where I start to loose understanding his this:

Code Snippet
Plaintext
wait 1;

Not really sure what this does at all and why it's there.

Code Snippet
Plaintext
for(i=0;i<fx_1.size;i++)

I understand what for() is and why it's there, but what's inside the bratchets it what confuses me the most out of anything, what is i=0? Does it define what FX is played on? So if I said i=4 then the first 4 entites would not emit FX?

Code Snippet
Plaintext
i<fx.size;

Not really sure, relating back to i=0 does it mean if I said i=4 then it will only play on only first 4 if I said i>fx.size?

Code Snippet
Plaintext
i++

Not a single clue what this means or does...


Of couse I am new to this, don't have a great understanding of it atm and that's why I would throw this out for scripters to maybe give me an idea?

Any info is appreciated. :D

Marked as best answer by Scobalula 10 years ago
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 14 September 2013
Last active: 5 years ago
Posts
1,895
Respect
Forum Rank
Zombie Destroyer
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
Personal Quote
BE ORIGINAL
Signature
×
MakeCents's Groups
Community Mapper Has released one or more maps to the UGX-Mods community which have been added to the UGX Map Manager.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
The wait 1; is pretty much useless. It just waits a second before playing the fx on each ent in the array.

Arrays in CodScript work, kind of two ways. I would compare them to a Python Dictionary and List behavior. Meaning they have order and indexes, as well as key > values.

Your probably thinking, thanks alot, that made no sense either, lol. Well here is the basic index set up that you are using.

The first index of the array is the 0th index.
The size of the array is how many key>value pairs it has.

Code Snippet
Plaintext

bo2_weapon_light()
{
fx_1 = GetEntArray("weapon_upgrade","targetname");

wait 1;
for(i=0;i<fx_1.size;i++)
playFx(level._effect["wall_weapon_light"], fx_1[i].origin);
}

i=0 means it is initializing the variable i as 0.
i++ says that after each loop change this var by one
the i<fx_1.size says to run this loop while i is less than the size of the fx_1 array. (while this statement is true)



So, to step through this loop as if the size of the array is 3:
First loop:
For i=0
(is i < fx_1.size) if so then continue the loop
play fx on the 0th ent origin

Second loop:
i++, so i = 1 now
is i < fx_1.size, if so then continue the loop
play fx on the 1th ent origin

Third loop:
i++, so i = 2 now
is i < fx_1.size, if so then continue the loop
play fx on the 2th ent origin

Fourth loop:
i++, so i = 3 now
is i < fx_1.size, if so then continue the loop BUT IT ISN'T (i=3 and the size = 3 so this statement i<fx_1.size is no longer true)
so stop and continue the rest of the function or whatever, in this case it is finished.


So we covered the 0th, 1th, and 2th indexes of the array, which is a size of 3.
The array looks something like this:
Code Snippet
Plaintext
fx_1{[0,ent],[1,ent],[2,ent]}
Spoiler: click to open...
which can also be portrayed as:
Code Snippet
Plaintext
fx_1[ent,ent,ent]
//    0,  1,  2      indexes


Key>Values work slightly differently. You don't iterate numerically. You use the string key you set up, like:

Code Snippet
Plaintext
myarray = [];
myarray["test"] = "this is a test";
iprintlnbold(myarray["test"]);
myarray["test2"] = "this is only a test";
iprintlnbold(myarray["test2"]);


The array looks something like this:
Code Snippet
Plaintext
myarray{["test","this is a test"],["test2","this is only a test"]}
Last Edit: September 21, 2015, 03:21:52 pm by MakeCents
broken avatar :(
×
broken avatar :(
OnionmanVere Bo21
Location: ieu dnt wnt 2 no
Date Registered: 27 September 2013
Last active: 7 days ago
Posts
1,864
Respect
Forum Rank
Zombie Destroyer
Primary Group
Community Mapper
My Groups
More
Personal Quote
ok
×
Scobalula's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Box Mappers Elite
Box Mappers Elite
Community Mapper Has released one or more maps to the UGX-Mods community which have been added to the UGX Map Manager.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Scobalula's Contact & Social Links
*above this post*
I appreciate the amount of time and effort you have put into typing this up, this pretty much explains a lot for me, thanks.
Last Edit: September 21, 2015, 03:36:22 pm by Scobalula
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 14 September 2013
Last active: 5 years ago
Posts
1,895
Respect
Forum Rank
Zombie Destroyer
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
Personal Quote
BE ORIGINAL
×
MakeCents's Groups
Community Mapper Has released one or more maps to the UGX-Mods community which have been added to the UGX Map Manager.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
I appreciate the amount of time and effort you have put into typing this up, this pretty much explains a lot for me, thanks.

No prob. Arrays are fun. Just wait until you get multidimensional arrays! (Arrays in arrays) Super fun.
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 9 years ago
Posts
2,789
Respect
Forum Rank
King of the Zombies
Primary Group
Community Daedra
My Groups
More
My Contact & Social Links
More
Signature
Let's keep this thread on topic from here on in. -DBZ

+1 to off-topic reply -DBZ

lmao. Too funny.

Goliath Script Placer: http://ugx-mods.com/forum/index.php/topic,11234.msg125257/topicseen.html#new

"...Christ, people. Learn C, instead of just stringing random characters
together until it compiles (with warnings)..."

-Linus Torvalds
×
daedra descent's Groups
Community Daedra
Community Daedra
daedra descent's Contact & Social LinksBlueSoviet
No prob. Arrays are fun. Just wait until you get multidimensional arrays! (Arrays in arrays) Super fun.

I hope that was sarcasm. Those things can be total hell if they get big enough. Lol
broken avatar :(
×
broken avatar :(
Location: fi
Date Registered: 25 June 2013
Last active: 1 year ago
Posts
3,997
Respect
Forum Rank
Eviscerator
Primary Group
UGX V.I.P.
My Groups
More
My Contact & Social Links
More
×
HitmanVere's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
UGX V.I.P.
UGX V.I.P.
Community Mapper Has released one or more maps to the UGX-Mods community which have been added to the UGX Map Manager.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
The wait 1; is pretty much useless. It just waits a second before playing the fx on each ent in the array.

I added the wait line due to sometimes script messing up for me, if I didnt do wait line. I think you told me this like year ago, when I was asking why some script didnt work, lol
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 14 September 2013
Last active: 5 years ago
Posts
1,895
Respect
Forum Rank
Zombie Destroyer
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
Personal Quote
BE ORIGINAL
×
MakeCents's Groups
Community Mapper Has released one or more maps to the UGX-Mods community which have been added to the UGX Map Manager.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
I hope that was sarcasm. Those things can be total hell if they get big enough. Lol

Lolol, no, I was totally serious. I really do enjoy them.  :D

I added the wait line due to sometimes script messing up for me, if I didnt do wait line. I think you told me this like year ago, when I was asking why some script didnt work, lol

Oh boy if I did, I am sorry, lol. So much learned in a year. In certain cases you do need a wait like that, but that is due to parallel threading or something like that, depending on how you scripted something (and obviously loops). Especially when using notifies, which I tend to avoid due to issues like that. In this case, you get the array and the script won't continue until the array is gathered, so immediately starting your for loop should not cause any issues. Your wait could go before getting the array, if you were spawning things or setting models or moving ents or something along those lines before this.
Last Edit: September 24, 2015, 12:22:25 pm by MakeCents
broken avatar :(
×
broken avatar :(
Location: gbMilton Keynes
Date Registered: 17 January 2014
Last active: 5 years ago
Posts
6,877
Respect
Forum Rank
Immortal
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
Signature
If you want scripts / features made for you, then contact me by PM or email / skype etc
it will cost you tho so if you have no intention of reciprocating don't even waste my time ;)
×
Harry Bo21's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Harry Bo21's Contact & Social LinksHarryBo000[email protected]HarryBo21
I added the wait line due to sometimes script messing up for me, if I didnt do wait line. I think you told me this like year ago, when I was asking why some script didnt work, lol
only need a wait in loops, and only if that loop doesnt already provide a wait

so

Code Snippet
Plaintext
while( 1 )
{
    wait 1;
}

is a loop or

Code Snippet
Plaintext
while( 1 )
{
    self waittill( "trigger", user );
}

doesnt need the wait, as the trigger itself has a delay on it anyway, which effectively is a wait

no wait would be required if doing this

Code Snippet
Plaintext
while( 1 )
{
    self waittill( "notify" );
}

because it would only be triggered once, but if you "wanted" to be absolutely safe, best place to put it is just after

Code Snippet
Plaintext
while( 1 )
{
    self waittill( "notify" );
    wait .1;
}
Last Edit: September 24, 2015, 07:45:03 am by Harry Bo21

 
Loading ...