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,805 views
broken avatar :(
×
broken avatar :(
Location: se
Date Registered: 30 July 2013
Last active: 3 weeks 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
I am just playing around with the "case" statement. I have not used this statement before so this is my first time. And I found this statement really useful. :D

Anyway, I am using this script which has a case statement.
Code Snippet
Plaintext
main
{
place1 = getEnt("place1","targetname");
place1 thread place_weapons("m9");
}

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

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

currentWeapon = players[i] GetCurrentWeapon();
if(currentWeapon == weap)
{
self trigger_off();

level.times_placed++;

if(level.times_placed == 1)
{
case "m9":
players[i] takeweapon("m9");
ice_model show();
ice_model setmodel("zombie_3rd_perk_bottle_doubletap");
self waittill("trigger", player);
players[i] giveweapon("m9_upgraded");
ice_model hide();
self trigger_on();
break;
                                }
                    }
          }
}
}
}
But when I am loading my map, I get a script compile error saying, "illegal case statement". What did I do wrong with the case statement?

Thanks in advance.
Last Edit: May 11, 2014, 09:25:55 am by Ege115
This topic contains a post which is marked as the Best Answer. Click here to view it.
broken avatar :(
×
broken avatar :(
Location: de
Date Registered: 6 August 2012
Last active: 4 years ago
Posts
277
Respect
Forum Rank
Mr. Elemental
Primary Group
Community Scripter Elite
My Groups
More
×
YaPh1l's Groups
Community Scripter Elite Has shown excellence and experience in the area of custom scripting in the UGX-Mods community.
YaPh1l's Contact & Social Links
case statements are only allowed within a switch block.

- Phil.
broken avatar :(
×
broken avatar :(
Location: se
Date Registered: 30 July 2013
Last active: 3 weeks 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
case statements are only allowed within a switch block.

- Phil.
Uhm, a what? So what exactly is it I need to change at the case statement? :o
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
Like this:

Code Snippet
Plaintext
main
{
place1 = getEnt("place1","targetname");
place1 thread place_weapons("m9");
}

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

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

currentWeapon = players[i] GetCurrentWeapon();
if(currentWeapon == weap)
{
self trigger_off();

level.times_placed++;

if(level.times_placed == 1)
{
switch(currentweapon)
{
case "m9":
players[i] takeweapon("m9");
ice_model show();
ice_model setmodel("zombie_3rd_perk_bottle_doubletap");
self waittill("trigger", player);
players[i] giveweapon("m9_upgraded");
ice_model hide();
self trigger_on();
break;
                                }
}
                    }
          }
}
}
}

EDIT: Really i'd just suggest an if statement instead of a case statement for what your trying to do. Case statements are primarily used as a way to return values, not do lengthy code.
Last Edit: May 11, 2014, 02:10:19 pm by daedra descent
broken avatar :(
×
broken avatar :(
Location: se
Date Registered: 30 July 2013
Last active: 3 weeks 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
Like this:

Code Snippet
Plaintext
main
{
place1 = getEnt("place1","targetname");
place1 thread place_weapons("m9");
}

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

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

currentWeapon = players[i] GetCurrentWeapon();
if(currentWeapon == weap)
{
self trigger_off();

level.times_placed++;

if(level.times_placed == 1)
{
switch(currentweapon)
{
case "m9":
players[i] takeweapon("m9");
ice_model show();
ice_model setmodel("zombie_3rd_perk_bottle_doubletap");
self waittill("trigger", player);
players[i] giveweapon("m9_upgraded");
ice_model hide();
self trigger_on();
break;
                                }
}
                    }
          }
}
}
}

EDIT: Really i'd just suggest an if statement instead of a case statement for what your trying to do. Case statements are primarily used as a way to return values, not do lengthy code.
Okey thank you, that seems to have fixed it. Now an another error pops up. The script compile error is saying,
"missing case statement"
And developer 1 says that it is something regarding those first three lines you often have in scripts.
Code Snippet
Plaintext
#include, etc
Is it an another file I need to include there? If so which one?
broken avatar :(
×
broken avatar :(
Location: usYork, SC
Date Registered: 15 March 2014
Last active: 5 years ago
Posts
214
Respect
Forum Rank
Mr. Elemental
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
Personal Quote
WaW Scriptor
Signature
WaW Scriptor
×
PROxFTW'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.
PROxFTW's Contact & Social LinksPROxFTWPROxFTWPROxFTWPROxFTW
No, nothing wrong with that more than likely. But make sure you add a default case statement. Most likely why that is happening is there is a value being returned that is not listed down.
Last Edit: May 11, 2014, 04:44:11 pm by PROxFTW
broken avatar :(
  • n123q45
  • Deleted Member
×
broken avatar :(
n123q45
This user is deleted :(
this is how a case statement is setup
Code Snippet
Plaintext
var = undefined; //the variable has to be set before the actual script

switch(var){ // var is the variable
  case "1": // what the first option the variable could be

  break; // how to end a case
 
  case "2": // what the second option the variable could be

  break;
}

this is used instead of lots of if else statements. you use this when the variable is set before this script. I used undefined to show that it has to be set before.
broken avatar :(
×
broken avatar :(
Location: se
Date Registered: 30 July 2013
Last active: 3 weeks 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
No, nothing wrong with that more than likely. But make sure you add a default case statement. Most likely why that is happening is there is a value being returned that is not listed down.
Hmm, well I still don't know exactly what I need to do, what value? :o I'm a noob.
Last Edit: May 11, 2014, 06:05:16 pm by Ege115
broken avatar :(
×
broken avatar :(
Location: de
Date Registered: 6 August 2012
Last active: 4 years ago
Posts
277
Respect
Forum Rank
Mr. Elemental
Primary Group
Community Scripter Elite
My Groups
More
×
YaPh1l's Groups
Community Scripter Elite Has shown excellence and experience in the area of custom scripting in the UGX-Mods community.
YaPh1l's Contact & Social Links
The value of the variable you "switch over". Although that shouldn't be causing any problems, it just wouldn't execute any case at all.

- Phil.
broken avatar :(
×
broken avatar :(
Location: se
Date Registered: 30 July 2013
Last active: 3 weeks 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
Well, then I have no idea what's wrong. I don't know how I should correct the script myself. D: I can't see anything wrong with it.
broken avatar :(
×
broken avatar :(
Location: usCali(fornia)
Date Registered: 21 December 2013
Last active: 4 years ago
Posts
418
Respect
Forum Rank
Perk Hacker
Primary Group
Member
My Contact & Social Links
More
Signature
The sound of God is the screech of tires, lights and magnets, bolts and wires. Strayed from the road, this very one, still to come. The sound of tires is the sound of God, the electric version.
×
mrpeanut188's Groups
mrpeanut188's Contact & Social Linksmrpeanut1881337p34nutmrpeanut188
Well, then I have no idea what's wrong. I don't know how I should correct the script myself. D: I can't see anything wrong with it.
Like said, it 'switches' to the value returned and executes the code. Let's say you have the case for 'm9' and 'thompson'. If you carry any other gun, presumably it'd pop out an error or do nothing. If it IS popping out an error, you have to add a default case so that if it isn't one of the listed guns it's execute the code in the default case.

C# Switch Example (Top box)
Last Edit: May 11, 2014, 06:22:38 pm by mrpeanut188
broken avatar :(
×
broken avatar :(
Location: se
Date Registered: 30 July 2013
Last active: 3 weeks 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
Like said, it 'switches' to the value returned and executes the code. Let's say you have the case for 'm9' and 'thompson'. If you carry any other gun, presumably it'd pop out an error or do nothing. If it IS popping out an error, you have to add a default case so that if it isn't one of the listed guns it's execute the code in the default case.

C# Switch Example (Top box)
Yay, I added this,
Code Snippet
Plaintext
default:
And the map loads without errors now. But when I hit the triggers, it doesn't take the weapon. (m9)

Here is the updated script if you wan tto see that.
Code Snippet
Plaintext
main
{
place1 = getEnt("place1","targetname");
place1 thread place_weapons("m9");
}

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

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

currentWeapon = players[i] GetCurrentWeapon();
if(currentWeapon == weap)
{
self trigger_off();

level.times_placed++;

if(level.times_placed == 1)
{
switch(currentweapon)
{
case "m9":
players[i] takeweapon("m9");
ice_model show();
ice_model setmodel("zombie_3rd_perk_bottle_doubletap");
self waittill("trigger", player);
players[i] giveweapon("m9_upgraded");
ice_model hide();
self trigger_on();
break;
                                        default:
                                }
}
                    }
          }
}
}
}
Thanks for the help so far, I am getting closer and closer to get it working. :D
broken avatar :(
×
broken avatar :(
Location: usCali(fornia)
Date Registered: 21 December 2013
Last active: 4 years ago
Posts
418
Respect
Forum Rank
Perk Hacker
Primary Group
Member
My Contact & Social Links
More
×
mrpeanut188's Groups
mrpeanut188's Contact & Social Linksmrpeanut1881337p34nutmrpeanut188
Not very good at scripting, but..

You call this
Code Snippet
Plaintext
place1 thread place_weapons("m9");

But the function is this
Code Snippet
Plaintext
place_weapons(weap)

Shouldn't it be
Code Snippet
Plaintext
place1 thread place_weapons(weap);
because it switches to the m9 inside of the function itself?
Last Edit: May 11, 2014, 06:56:31 pm by mrpeanut188
broken avatar :(
×
broken avatar :(
Location: se
Date Registered: 30 July 2013
Last active: 3 weeks 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
Not very good at scripting, but..

You call this
Code Snippet
Plaintext
place1 thread place_weapons("m9");

But the function is this
Code Snippet
Plaintext
place_weapons(weap)

Shouldn't it be
Code Snippet
Plaintext
place1 thread place_weapons(weap);
because it switches to the m9 inside of the function itself?
Hmm, that can't be the issue as this script works in other cases. This time I am making it with the case statement, but it just doesn't takes the weapon.
broken avatar :(
×
broken avatar :(
Location: usYork, SC
Date Registered: 15 March 2014
Last active: 5 years ago
Posts
214
Respect
Forum Rank
Mr. Elemental
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
Personal Quote
WaW Scriptor
×
PROxFTW'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.
PROxFTW's Contact & Social LinksPROxFTWPROxFTWPROxFTWPROxFTW
Test this
Code Snippet
Plaintext
main()
{
place1 = getEnt( "place1", "targetname" );
place1 thread place_weapons( "m9" );
}

place_weapons( Weap )
{
ice_model = GetEnt( "ice_model","targetname" );

while( 1 )
{
while( isDefined( self ) )
{
ice_model hide();
self waittill( "trigger", player );

CurrWeap = player GetCurrentWeapon();
if( CurrWeap == Weap )
{
self trigger_off();
level.times_placed++;

if( level.times_placed == 1 )
{
switch( CurrWeap )
{
case "m9":
player takeweapon( CurrWeap );
ice_model show();
ice_model setmodel( "zombie_3rd_perk_bottle_doubletap" );
self waittill( "trigger", player );
player giveweapon( CurrWeap + "_upgraded" );
ice_model hide();
self trigger_on();
break;

                        default:
                        break;
                    }
}           
        }
}
}
}

 
Loading ...