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

How to do Dynamic Variables in GSC?

broken avatar :(
Created 7 years ago
by MegaMech43
0 Members and 1 Guest are viewing this topic.
1,709 views
broken avatar :(
×
broken avatar :(
Location: caCanada, Eh
Date Registered: 24 November 2016
Last active: 6 years ago
Posts
85
Respect
Forum Rank
Rotting Walker
Primary Group
Member
My Contact & Social Links
More
×
MegaMech43's Groups
MegaMech43's Contact & Social Linksmegamechmegamech.net
I want to control when a hud activates/deactives per player. (another function changes i.alpha when triggered)
The problem is if I run i.alpha = 1; it will change everybodies huds.

I know two possible solutions. Dynamic variables or
Code Snippet
Plaintext
players = getplayers();
for players.size {
players[i].hud.alpha = 0; //Any idea if there is an index of 'player' that makes this line of code possible?
}

Dynamic Variable:
This method throws an error. This way should work because each time it creates a new hud object with a new variable.
Anyone know a different method that may work?

Code Snippet
Plaintext
function hud() {
players = getplayers();
level.hud = [];
for (i=0; i<players.size; i++) {
abc = asdf+i;
level.hud[i] = NewClientHudElem(players[i]);//I also tried level.i = NewCli... (This compiled but didn't work.)
level.hud[i].foreground = true;
level.hud[i].fontScale = 1.5;
level.hud[i].fontType = "default"; //etc.
level.i.sort = 1;
level.i.hidewheninmenu = true;
level.i.alignX = "left";
level.i.alignY = "bottom";
level.i.horzAlign = "left";
level.i.vertAlign = "bottom";
level.i.x = 35;
level.i.y -= 125;
level.i.alpha = 1; //eventually be 0
level.i SetText("Stocks: "+level.cash); //Yes, you will be able to collect interest at a 'bank' in my map.
}
}
Last Edit: January 19, 2017, 01:09:55 am by MegaMech43
Marked as best answer by MegaMech43 7 years ago
broken avatar :(
×
broken avatar :(
Location: nlApeldoorn
Date Registered: 17 December 2013
Last active: 1 year ago
Posts
1,187
Respect
1,404Add +1
Forum Rank
Zombie Colossus
Primary Group
Community Scripter Elite
My Groups
More
My Contact & Social Links
More
Personal Quote
It aint much, if it aint Dutch
Signature
×
BluntStuffy's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Community Scripter Elite Has shown excellence and experience in the area of custom scripting in the UGX-Mods community.
Oil Rig Beta Access
Oil Rig Beta Access
BluntStuffy's Contact & Social LinksBluntstuffy@BluntZombieBluntStuffyStuffyZombie
Code Snippet
Plaintext
function hud() 
{
players = getplayers();
for (i=0; i<players.size; i++)
{
hud[i] = NewClientHudElem(players[i]);
hud[i].foreground = true;
hud[i].fontScale = 1.5;
hud[i].fontType = "default";
hud[i].sort = 1;
hud[i].hidewheninmenu = true;
hud[i].alignX = "left";
hud[i].alignY = "bottom";
hud[i].horzAlign = "left";
hud[i].vertAlign = "bottom";
hud[i].x = 35;
hud[i].y -= 125;
hud[i].alpha = 1; //eventually be 0
hud[i] SetText("Stocks: "+level.cash);
players[i].my_hud = hud[i];
}
}


function change_myhud_alpha()
{
players = getplayers();
for (i=0; i<players.size; i++)
{
players[i].my_hud.alpha = 0;
}
}

broken avatar :(
×
broken avatar :(
Location: caCanada, Eh
Date Registered: 24 November 2016
Last active: 6 years ago
Posts
85
Respect
Forum Rank
Rotting Walker
Primary Group
Member
My Contact & Social Links
More
×
MegaMech43's Groups
MegaMech43's Contact & Social Linksmegamechmegamech.net
Code Snippet
Plaintext

hud[i] = NewClientHudElem(players[i]);
players[i].my_hud = hud[i];
function change_myhud_alpha() {
players[i].my_hud.alpha = 0;
}

That solution worked! Thank you. I was so close to the answer haha.
That one had me stumped.
"When in doubt, create your own index"?

Is it possible to create a new line with SetText.
Like SetText("Stock: "+level.cash+"\n Interest:"+level.interest);
Last Edit: January 19, 2017, 01:55:34 am by MegaMech43

 
Loading ...