Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-01-2011, 02:12 AM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
Switch and case?

What does this mean, and how do I use it. Its in the end of my staff boots script?
PHP Code:
function onTimeOut()

{

 if (
this.staff_boots == "on")

  {

   for (
a=0a<4a++)

    {

     if (
keydown(a))

      {

       switch(
a)

        {

          case 
"0":

           
player.y-=this.speed;

           break;

          case 
"1":

           
player.x-=this.speed;

           break;

          case 
"2":

           
player.y+=this.speed;

           break;

          case 
"3":

           
player.x+=this.speed;

           break;

        }

      }

    }

  }

 
setTimer(0.05);


__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #2  
Old 03-01-2011, 02:26 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
It's just a different way to write an if-else when you're working with a single variable (a in this case).

That switch statement in your code translates to

PHP Code:
  if (== "0") { 
    
player.-= this.speed
  } else if (
== "1") {
    
player.-= this.speed
  } else if (
== "2") {
    
player.+= this.speed
  } else if (
== "3") {
    
player.+= this.speed
  } 
You can do slightly more complicated logic with switch statements, but I personally think those more complex uses of switch just makes things more confusing and bug-prone.
Reply With Quote
  #3  
Old 03-01-2011, 07:24 AM
MrOmega MrOmega is offline
One More Time
MrOmega's Avatar
Join Date: Aug 2010
Location: TN, USA
Posts: 631
MrOmega is an unknown quantity at this point
Send a message via AIM to MrOmega Send a message via MSN to MrOmega Send a message via Yahoo to MrOmega
Try using the forum's search function, may save you some time. Search for 'Spoils of the Switch'. It helped me a lot when I first read it.
__________________
Time is the fire in which we burn...
Up, Up, Down, Down, Left, Right, Left, Right, B, A, Select, Start! Now I got 99 LIVES!!!
Reply With Quote
  #4  
Old 04-29-2011, 08:51 PM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
For staff boots you will never need to know this.. instead use something more along the lines of:

PHP Code:
for ( i=0i<4i++ ) {
  if ( 
keydown(i) ) {
    
player.+= vecx(i) * this.speed;
    
player.+= vecy(i) * this.speed;
  }

Vec X/Y would give you -1,0,1 depending on direction. I am not completly sure how to explain it to you but I understand how it works. If im not mistaken its for finding vectors?

This greatly reduces your script length and makes it easier to modify.
Reply With Quote
  #5  
Old 04-29-2011, 10:30 PM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
I'm not a particularly big fan of that transformation. I find the if statement much clearer.
Reply With Quote
  #6  
Old 04-29-2011, 11:05 PM
MrOmega MrOmega is offline
One More Time
MrOmega's Avatar
Join Date: Aug 2010
Location: TN, USA
Posts: 631
MrOmega is an unknown quantity at this point
Send a message via AIM to MrOmega Send a message via MSN to MrOmega Send a message via Yahoo to MrOmega
Nice job bringing up another old thread!

Anywho, vex/vecy will return the direction in which the operation points. So, let's say your xVal is 32 and you want it to be 30. So vecx( 32-30) would give you -1 since you are to move left. Up would -1 of vecy and so forth, if you aren't moving it will return 0. By graal magic it works with direction values too, 0-3. So if your face south your vecx would be 0 and vecy would be 1.
__________________
Time is the fire in which we burn...
Up, Up, Down, Down, Left, Right, Left, Right, B, A, Select, Start! Now I got 99 LIVES!!!
Reply With Quote
  #7  
Old 04-30-2011, 12:05 AM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
Hi Switch, who's Case?

gj @ bumping an old thread for no reason
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #8  
Old 04-30-2011, 12:15 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Is providing a better solution a bad or useless thing to do?
Reply With Quote
  #9  
Old 05-13-2011, 10:14 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by scriptless View Post
Vec X/Y would give you -1,0,1 depending on direction. I am not completly sure how to explain it to you but I understand how it works. If im not mistaken its for finding vectors?
Common question, posted a thread about it: http://forums.graalonline.com/forums...47#post1649547
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #10  
Old 05-14-2011, 07:20 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Thanks for reference Tigairius, will come in hand I'm sure.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:05 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.