Game Development Community

case

by rennie moffat · in Torque Game Builder · 08/19/2009 (10:44 am) · 22 replies

I am in a tut which uses the term "case" in an updatePlayerAnimation function. I am unsure what "case means as when I search it I get other tuts but no definition. Any one have a quick explanation?


function updatePlayerAnimation()
{
   // Grab the desired direction of movement.
   %move = $moveRight - $moveLeft;
   %jump = $jump;
   
   // The state machine. The current state of the player is determined, and
   // based on some rules that can change that state, the state is updated.
   switch ($player.state)
   {
      // Standing still.
      case $playerStandState:
         // If suddenly the player is not a surface, start falling.
         if ($runSurface < 0)
            setPlayerState($playerStandFallState);

About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.

Page «Previous 1 2
#1
08/19/2009 (11:09 am)
It is a switch/case statement. It is a pretty standard control statement in most programming languages.

http://tdn.garagegames.com/wiki/TorqueScript#Control_Statements

#2
08/19/2009 (11:11 am)
so switch is the command, case is the state or condition?
#3
08/19/2009 (11:25 am)
the "switch" keyword defines the variable you wish to inspect. The "case" statement defines "when the variable equals this case" then perform an operation.

It's a way of doing a more readable

if(%x == 1)
{
}
else if(%x == 2)
{
}
else if(%x == 3)
{
}
else if(%x == 4)
{
}
else
{
}

which would equate to

switch(%x)
{
   case 1:
     ...
   case 2:
     ...
   case 3:
     ...
   case 4:
     ...
}
#4
08/19/2009 (11:29 am)
ok, so say I wanted to use this in an animation function. IE. I want to set up all possible animations for a charater in one function. Would this be apprpriate?

Ex.
function Player::switchAnimation(%this, %dir)  
{  
   switch$(%dir)  
   {  
      case "up":  
         %animation = "heli_top" @ %animation;  
         %this.setAnimation(%animation);  
          
      case "down":  
         %animation = "heli_front" @ %animation;  
         %this.setAnimation(%animation);

My only question is, how does it know which one is appropriate to call? Where would I put the conditions?

#5
08/19/2009 (11:33 am)
ps.
the creator of this code used this switch case to first of all define his movement as well.

function Player::move(%this, %dir)  
{  
   switch$(%dir)  
   {  
      case "up":    
         %this.setLinearVelocityY(-$pSpeed);  
         %this.switchAnimation(up);
#6
08/19/2009 (11:55 am)
The case statements are your conditions.

So if %dir == "up" then the code underneath case "up": will be executed.

if %dir == "down": then the code underneath case "down": will be executed.

..and so on.


#7
08/19/2009 (1:13 pm)
Quote:
ps.
the creator of this code used this switch case to first of all define his movement as well.

1. function Player::move(%this, %dir)
2. {
3. switch$(%dir)
4. {
5. case "up":
6. %this.setLinearVelocityY(-$pSpeed);
7. %this.switchAnimation(up);

thats why i said you should take some programming classes... now, you're quoting some code i worte in your threads, trying to use it, but NOT AT ALL understanding it, even tho, its pretty basic.


Quote:
ok, so say I wanted to use this in an animation function. IE. I want to set up all possible animations for a charater in one function. Would this be apprpriate?

Ex.
view plainprint?

1. function Player::switchAnimation(%this, %dir)
2. {
3. switch$(%dir)
4. {
5. case "up":
6. %animation = "heli_top" @ %animation;
7. %this.setAnimation(%animation);
8.
9. case "down":
10. %animation = "heli_front" @ %animation;
11. %this.setAnimation(%animation);
do you even understand whats going on there?... cuz, while it DOES indeed wrk and all, its some custom code, that unless you make it fit on your particular case, wont work for you.

...and, still, you pretend to make my posts look like a rant... when you know that my suggestion is true.
#8
08/19/2009 (1:39 pm)
uh, sure, whatever you say.
#9
08/19/2009 (2:36 pm)
prove me wrong then!.... you dont even know what a Switch sentence is... and yet you claim you know exactly what that piece of code does and works?... dont make me laugh man!.
#10
08/19/2009 (3:00 pm)
Pasting from other threads where this issue is cropping up

@All - Keep this civil. I really cannot stress how important this is.

No more threats
No more harsh language
No more flame baiting

@Ehrlichmann - You are doing a great job helping us out in the forums. You are posting some great feedback and answering support questions. I really do appreciate that.

However, you need to lay off the new people. I know you might be frustrated repeating yourself. Welcome to our world (documentation and support). The point is, every new Torque user (or new to game development, period) is going to ask the same questions. Sometimes a user will ask the same question, but that's usually because they have not fully grasped some programming concepts.

I would really like for you to keep helping us, as it is the defining feature of our community. If you are getting frustrated with an individual, WALK AWAY. Do not go after them in every thread.

@rennie - Slow down. The others are posting accurate information. Take the time to dissect what they are saying and apply it to your own work. You might need to go back over the tutorials a few times to get a full understanding of what's going on. You will get there, and there are more TorqueScript docs coming, but you can also seek information outside of our website to get definitions for basic programming.

The extension of TorqueScript is CS for a reason: C-Script. It is very similar to C or C++ syntax, which means things like switch statements have roots in C. While the syntax is different, the application is the same.
#11
08/19/2009 (3:21 pm)
@ ehrilchmann
Quote form Micheal Perry
"I know you might be frustrated repeating yourself. Welcome to our world (documentation and support). "

I agree, but you see, you dont have to answer then. Like I said from the beginning, if you dont think it deserves an answer, don't answer it. That's all. Don't answer telling me that Im screwing up, or not doing it right? Again, I ask to know. What is the point of me thinking for an hour if I should ask a question or just asking it, and letting someone eventually answer what are, in my case very low level questions.

So yes I am learning and believe me I am way further ahead then perhaps you are giving me credit for. Again, my main issue is, if my question is a two second answer, answer it, or dont, but don't give me your persoanl take on what I am doing and who a I am. It just wastes my time and energy.


@ all
So sorry for this, I hope you can see why I was frustrated with this particular members habits.
#12
08/19/2009 (3:24 pm)
@ micheal,
no problem, I am believe me i have gone over the tuts, and still am, with noticeable improvement week by week. I consider a board to be like a friend in the room who knows about what I am studying. I asked 3 question over 4 hours. That is not really a lot.



But Believe me, I am doing nothing but trying to raise my own prestige and Torques through good game design and I am well on my way.
#13
08/19/2009 (3:25 pm)
i guess im better off not answering shit in the forums no more... but i hope i can get some if needed afterwards.

i guess my help its not really needed, but still as a licensee, i guess i can still have some, if something comes up.

laters.
#14
08/19/2009 (3:32 pm)
stop crying, see your the one crying and you were the one upsetting me. Guess I spotted you.

I am sure your help is more then appreciated. I appreciate it too, greatly, but only when you answer the question, not when you tell me your personal thoughts about me. THAT, I am not interested in. Capiche?


If you want to answer, go for it, but just don't tell me negative things about me, that YOU think are true, but are not, thats all I am saying dude. I don't need message room drama. believe me. I just wanna find out what I need to thats all.
#15
08/19/2009 (3:42 pm)
dude... if i cry or dont, it NONE OF YOUR DAMNED BIZZ.

i know what you want, and im not providing, even if i have it.... so ya, capiccico. (you dont even know how to write in italian...).

and i'd like to answer lots of things,sometimes i just dont have enough time (even tho it doesnt look like it), or dont know the answer... but one thing i know for sure,.is that you DONT KNOW what you think you know... or you wouldnt be asking for it a billion times a week.

now, drama?... dont worry, no more drama from me, trust me, you wont hear from me ever again. after all i dont wanna have a hell at my door step, i still have some kids to make and raise.
#16
08/19/2009 (3:44 pm)
quote
ehrlch
"you wont hear from me ever again"

ok thanks but, thats what you said yesterday.
#17
08/19/2009 (3:50 pm)
and thats what i say today and tomorrow and whenever i FUCKING want... unless i get banned from here. how 'bout that? dont wanna read me, your problem, but you'll hear from me til the day you die.
#18
08/19/2009 (3:53 pm)
can someone call an ambulance please.
i think we got a bad case over here.
#19
08/19/2009 (3:55 pm)
is it for you, or what?... cuz i see no bad case here.... you might need your medication now. here, take some water... dont choke with the pills-
#20
08/19/2009 (3:57 pm)
Would you mind using a chat software for your conversation?
Page «Previous 1 2