Jump to content


Photo

Case () && (): //movement


  • Please log in to reply
4 replies to this topic

#1 vv3k70r

vv3k70r

    GMC Member

  • New Member
  • 103 posts

Posted 26 September 2009 - 05:26 PM

Fellows,

I have:
switch (keyboard_key)
{



	case (vk_up):
// blablabla, break and such things that works

How to write corectly "&&" that will work?

I mean for example:
case (vk_up) && (vk_left):

Do I suspected corectly that one key case should be after than two key cases? Mean

case (vk_up) && (vk_left):
	case (vk_up):

instead of

	case (vk_up):
	case (vk_up) && (vk_left):

Ok, what to do that up and left will give me upleft movement? because up is working and left too...

Edited by vv3k70r, 26 September 2009 - 05:43 PM.

  • 0

#2 moomoo112

moomoo112

    GMC Member

  • New Member
  • 663 posts
  • Version:GM7

Posted 26 September 2009 - 05:28 PM

i belive the && has to be inside the parenthesis as well
'case(vk_up && vk_left)'
  • 0

#3 Davve

Davve

    Procrastinator

  • GMC Member
  • 3665 posts
  • Version:GM8.1

Posted 26 September 2009 - 05:34 PM

keyboard_key is a variable, and a variable can only hold one value so...

if (keyboard_check(vk_up) && keyboard_check(vk_down)) {
	 show_message("You pressed Up and Down at the same time! o.O")
}

I'm afraid you can't use switch here..

EDIT:
Use this if you want 8 direction movement:
x+=keyboard_check(vk_right)*4
x-=keyboard_check(vk_left)*4
y+=keyboard_check(vk_down)*4
y-=keyboard_check(vk_up)*4

Edited by davve941018, 26 September 2009 - 05:37 PM.

  • 0

#4 vv3k70r

vv3k70r

    GMC Member

  • New Member
  • 103 posts

Posted 26 September 2009 - 05:42 PM

Sh&ยค%#, I had such suspiction that CASE is not good in this case...

I know that left, right and such has values, but I think IF will be more realiable.

I just was thinking that meybe someone have fixed this that way. Good to know that I was going wrong way before get to far ^_^

Thank You for help fellows.
  • 0

#5 skull13

skull13

    GMC Member

  • New Member
  • 241 posts

Posted 26 September 2009 - 05:47 PM

I had this issue once. I fixed it.

Here:
switch *variable name ONLY*
   {
   case *whatever:
   case *whatever else,but same result*:
   Bla bla bla code does stuff
   break
   }

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users