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

case statement

HOT
broken avatar :(
Created 10 years ago
by Ege115
0 Members and 1 Guest are viewing this topic.
4,832 views
broken avatar :(
×
broken avatar :(
drago
Location: mx
Date Registered: 5 July 2013
Last active: 4 years ago
Posts
941
Respect
Forum Rank
The Decider
Primary Group
Member
My Contact & Social Links
More
×
jjbradman's Groups
jjbradman's Contact & Social Linksjjbradmanjjbradmanjjbradman
dont pass the string "m9" to the other funtion. instead define it inside the other funtion. i got problems with switch in that case where all the values inside the switch block would get executed
broken avatar :(
×
broken avatar :(
[UGX] Founder
Location: usBay Area, California
Date Registered: 24 June 2011
Last active: 9 months ago
Posts
5,551
Respect
6,691Add +1
Forum Rank
Immortal
Primary Group
UGX Administrator
My Groups
More
My Contact & Social Links
More
Signature
If Java had true garbage collection, most programs would delete themselves upon execution.
×
treminaor's Groups
UGX Administrator
UGX Team Member
UGX Site Moderator Has the ability to issue warnings to users, edit and remove posts from the forum and to move topics to other boards. Upholds the rules of the forum. Moderates Chat Rooms.
i got problems with switch in that case where all the values inside the switch block would get executed
That would be because you didn't place break statements at the end of each case.
broken avatar :(
×
broken avatar :(
Location: se
Date Registered: 30 July 2013
Last active: 1 day ago
Posts
517
Respect
Forum Rank
Zombie Enslaver
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
×
Ege115's Groups
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Ege115's Contact & Social LinksEge115
That would be because you didn't place break statements at the end of each case.
More case statements is exactly what I am doing. this is the complete whole script if you want to see that.
And I tried your script PROxFTW, but it didn't take the weapon either. :/
Code Snippet
Plaintext
main()
{
place1 = getEnt( "place1", "targetname" );
        place2 = getEnt( "place2", "targetname" );
        place3 = getEnt( "place3", "targetname" );
        place4 = getEnt( "place4", "targetname" );

place1 thread place_weapons( "m9" );
place2 thread place_weapons( "m40a3" );
place3 thread place_weapons( "aug" );
place4 thread place_weapons( "g36c" );
}

place_weapons(weap)
{
ice_model = GetEnt("ice_model","targetname");
fire_model = GetEnt("fire_model","targetname");
elec_model = GetEnt("elec_model","targetname");
wind_model = GetEnt("wind_model","targetname");

while(1)
{
while(isDefined(self))
{
players = get_players();
for (i = 0; i < players.size; i++)
{
ice_model hide();
fire_model hide();
elec_model hide();
wind_model hide();
self waittill("trigger", player);

currentWeapon = player GetCurrentWeapon();
if(currentWeapon == weap)
{
//self trigger_off();

level.times_placed++;

if(level.times_placed == 1)
{
currentweapon = undefined;

switch(currentweapon)
{
case "m9":
players[i] takeweapon(currentweapon);
ice_model show();
ice_model setmodel("zombie_3rd_perk_bottle_doubletap");
self waittill("trigger", player);
players[i] giveweapon(currentweapon + "_upgraded");
ice_model hide();
break;
default:
break;
}

switch(currentweapon)
{
case "m40a3":
players[i] takeweapon(currentweapon);
fire_model show();
fire_model setmodel("zombie_3rd_perk_bottle_sleight");
self waittill("trigger", player);
players[i] giveweapon(currentweapon + "_upgraded");
fire_model hide();
break;
default:
break;
}

switch(currentweapon)
{
case "aug":
elec_model show();
players[i] takeweapon(currentweapon);
elec_model setmodel("zombie_3rd_perk_bottle_revive");
self waittill("trigger", player);
players[i] giveweapon(currentweapon + "_upgraded");
elec_model hide();
break;
default:
break;
}

switch(currentweapon)
{
case "g36c":
wind_model show();
players[i] takeweapon(currentweapon);
wind_model setmodel("zombie_3rd_perk_bottle_jugg");
self waittill("trigger", player);
players[i] giveweapon(currentweapon + "_upgraded");
wind_model hide();
break;
default:
break;
}
}
}
}
}
}
}
Isn't it wierd that it just WONT work even if the script says that it will take the weapon the player has? :/
Last Edit: May 12, 2014, 05:06:20 am by Ege115
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 8 years ago
Posts
2,790
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
Because your not using the case statement right. it should be something like this:

Code Snippet
Plaintext
switch(whatever)
{
case "whatever1":
// do whatever here
break;
case "whatever2":
// do whatever here
break;
case "whatever3":
// do whatever here
break;
}

again, i really suggest just using an if statement for all of this.

EDIT: Thought i'd make a little example to show why & the difference between the switch and if statements.

Code Snippet
Plaintext
switch_example(example)
{
if(!isdefined(example) )
{
example = "whatever1";
}
switch(example)
{
case "whatever1":
// do whatever here
break;
case "whatever2";
// do whatever here
break;
case "whatever3":
// do whatever here
break;
}
}
if_example(example)
{
if(!isdefined(example) )
{
example = "whatever1";
}

if(example == "whatever1")
{
// do whatever here
}
if(example == "whatever2")
{
// do whatever here
}
if(example == "whatever3")
{
// do whatever here
}
}

The cases only act as a separate if statement for each possibility. The only difference(i think) is that the switch function's different cases can apply to different entities at the same time while if statements can't.
Last Edit: May 12, 2014, 05:32:47 am by daedra descent
broken avatar :(
×
broken avatar :(
[UGX] Founder
Location: usBay Area, California
Date Registered: 24 June 2011
Last active: 9 months ago
Posts
5,551
Respect
6,691Add +1
Forum Rank
Immortal
Primary Group
UGX Administrator
My Groups
More
My Contact & Social Links
More
×
treminaor's Groups
UGX Administrator
UGX Team Member
UGX Site Moderator Has the ability to issue warnings to users, edit and remove posts from the forum and to move topics to other boards. Upholds the rules of the forum. Moderates Chat Rooms.
More case statements is exactly what I am doing. this is the complete whole script if you want to see that.
And I tried your script PROxFTW, but it didn't take the weapon either. :/

Isn't it wierd that it just WONT work even if the script says that it will take the weapon the player has? :/
The point of the switch case is that there are multiple outcomes based on the value of the variable you are switching, so I combined all of your cases into one switch statement.

Code Snippet
Plaintext
 
switch(currentweapon)
{
case "m9":
players[i] takeweapon(currentweapon);
ice_model show();
ice_model setmodel("zombie_3rd_perk_bottle_doubletap");
self waittill("trigger", player);
players[i] giveweapon(currentweapon + "_upgraded");
ice_model hide();
break;
case "m40a3":
players[i] takeweapon(currentweapon);
fire_model show();
fire_model setmodel("zombie_3rd_perk_bottle_sleight");
self waittill("trigger", player);
players[i] giveweapon(currentweapon + "_upgraded");
fire_model hide();
break;
case "aug":
elec_model show();
players[i] takeweapon(currentweapon);
elec_model setmodel("zombie_3rd_perk_bottle_revive");
self waittill("trigger", player);
players[i] giveweapon(currentweapon + "_upgraded");
elec_model hide();
break;
case "g36c":
wind_model show();
players[i] takeweapon(currentweapon);
wind_model setmodel("zombie_3rd_perk_bottle_jugg");
self waittill("trigger", player);
players[i] giveweapon(currentweapon + "_upgraded");
wind_model hide();
break;
default:
break;
}
broken avatar :(
×
broken avatar :(
Location: se
Date Registered: 30 July 2013
Last active: 1 day ago
Posts
517
Respect
Forum Rank
Zombie Enslaver
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
×
Ege115's Groups
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Ege115's Contact & Social LinksEge115
Oh, thank you so much it worked! I saw what I did wrong now, lol.
Well, now I have learned how "case" works, now what's next I need to learn in scripting? :D

Thank you all of you, I give you all each +1. ;)
broken avatar :(
  • n123q45
  • Deleted Member
×
broken avatar :(
n123q45
This user is deleted :(
the next thing you should learn is arrays

 
Loading ...