Jump to content


Photo

Logic bug?


  • This topic is locked This topic is locked
25 replies to this topic

#1 OzzyEx

OzzyEx

    GMC Member

  • GMC Member
  • 151 posts
  • Version:GM8

Posted 11 February 2012 - 12:36 PM

Hey all,


Here I am with another problem..this one really pisses me off and since I tried everything but wasn't able to solve it, I decided to post here in hope that some of you may help me.

Okay, lets get started:
Im making a beat-em-up game with some basic functions such as Left,Right,Up and some other letters.. Now, Ive made a keypress event (Z) which is supposed to change into another sprite (Punch). The thing is, when I first start the game, then i would be able to do it, meaning, sprite WOULD change and the button would respond. But right after I make a right move, after I move to the right or use the right key, then it would somehow block my Z key and I wouldn't be able to do it again. But if I turned to the left, (if I used the left key), then my punch animation would work. So clearly, something is blocking my sprite changing action on Z key with walking action on keypress right. But what? I tried to find it but I dont see anything thats causing this issue.

Here is the code of my Keyboard event right:

if keyboard_check(vk_left) then exit
scaleX = 1
if(attack=0)
if(set=1)
{
time=time+1
if(time/5 && time<50)
{
hspeed=hspeed+0.1
image_speed=image_speed+0.0025
}
}

if(delaycon=1 && set=0 && dusttimer=0)
{

if not(walkingcon=1)
delay=delay+1

sprite_index = Switch
image_xscale = scaleX
if(delay>5 && delay<10)
{
image_xscale = scaleX
}
if(delay>10){
hspeed=0
walkingcon=1
time=1
set=1
delay=0
hspeed=4
sprite_index = run_Left_right
image_xscale = scaleX
image_speed=0.05;
delaycon=0
}
}

background_hspeed[0]= 0.1;
background_hspeed[1]= 0.2;
background_hspeed[2]= 0.3;
background_hspeed[3]= 0.5;
background_hspeed[4]= 0;



And here is the code of my Key Press event right

if walkingcon != 0 then exit
if delay != 0 then exit
if keyboard_check(vk_left) then exit
if(attack=0)
if(hspeed=0)
if not(keyboard_check(vk_left))
if not(walkingcon=2)
{
walkingcon=1
time=1
set=1
hspeed=2
sprite_index = run_Left_right
image_xscale = scaleX
image_speed=0.05;
}

delay=0

if(hspeed<0.2)
if(walkingcon=2)
{
delaycon=1
}

scaleX = 1



Im also going to provide my step event to you, since im using it with the movement actions to speed up my character, it may come in handy.
if(walkingcon=2)
time=time+1



if(attack=0)
{
if(set=0)
{
if(time/5 && walkingcon=2)
 {
hspeed=hspeed+0.1
 }
if (hspeed>0.2)
 {
walkingcon=0
sprite_index = stand_left_right
image_xscale = scaleX
image_speed = 0.1
hspeed=0
time=0
 }
}
if(set=1)
{
if(time/5 && walkingcon=2)
 {
hspeed=hspeed-0.1
 }

if (hspeed<0.2)
 {
walkingcon=0
sprite_index = stand_left_right
image_xscale = scaleX
image_speed = 0.1
hspeed=0
time=0
 }
}
}



And for the key press event Z, its just an sprite changing action.
Please, if you can figure this out, post below i really need it, and i need it fast.
Thanks a lot in advance!!!

Cheers!

Edited by OzzyEx, 11 February 2012 - 12:38 PM.

  • 0

#2 amiel

amiel

    GMC Member

  • GMC Member
  • 1117 posts
  • Version:Unknown

Posted 11 February 2012 - 05:54 PM

try editing your statement like this:
if(attack=0) and 
if(hspeed=0) and 
if not(keyboard_check(vk_left)) and
if not(walkingcon=2) and
There are factors affecting the game,like from other pc,it doesn't allow you to press and hold 3 buttons at once.
:whistle:
  • 0

#3 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2300 posts
  • Version:GM7

Posted 11 February 2012 - 10:40 PM

Actually post both the Z and left code, doesn't matter how simple. Kinda hard to debug it with only one of the three parts of the problem.
  • 0

#4 OzzyEx

OzzyEx

    GMC Member

  • GMC Member
  • 151 posts
  • Version:GM8

Posted 12 February 2012 - 09:32 AM

Sure, here:

Keyboard event LEFT

if keyboard_check(vk_right) then exit
scaleX = -1
if(attack=0)
if(set=0)
{
time=time+1
if(time/5 && time<50)
{
hspeed=hspeed-0.1
image_speed=image_speed+0.0025
}
}
if(delaycon=1 && set=0 && dusttimer=0)
{

if not(walkingcon=1)
delay=delay+1

sprite_index = Switch
image_xscale = -scaleX
if(delay>5 && delay<10)
{
image_xscale = scaleX
}
if(delay>10){
hspeed=0
walkingcon=1
time=1
set=1
delay=0
hspeed=4
sprite_index = run_Left_right
image_xscale = -scaleX
image_speed=0.05;
delaycon=0
}
}

background_hspeed[0]= 0.1;
background_hspeed[1]= 0.2;
background_hspeed[2]= 0.3;
background_hspeed[3]= 0.5;
background_hspeed[4]= 0;


Keyboard press event LEFT

if walkingcon != 0 then exit
if delay != 0 then exit
if keyboard_check(vk_right) then exit
if(attack=0)
if(hspeed=0)
if not(keyboard_check(vk_right))
if not(walkingcon=2)
{
walkingcon=1
time=1
set=0
hspeed=-2
sprite_index = run_Left_right
image_xscale = scaleX
image_speed=0.05;
}

delay=0

if(hspeed>-0.2)
if(walkingcon=2)
{
delaycon=1
}



if(attack=0)
if(set=0)
{
time=time+1
if(time/5 && time<50)
{
hspeed=hspeed-0.1
image_speed=image_speed+0.0025
}
}
scaleX = -1


Keyboard LEFT Release

if(attack=0)
if(set=0)
{
sprite_index = Slowdown_left_right
image_speed=0.2;
image_xscale = scaleX
walkingcon=2
hspeed=hspeed+2
}


Keyboard RIGHT Release

if(attack=0)
if(set=1)
{
sprite_index = Slowdown_left_right
image_speed=0.2;
image_xscale = scaleX
walkingcon=2
hspeed=hspeed-2
}


Create - variables and stuff


sprite_index = stand_left_right;
image_index = 0;
image_speed = 0.4;

walkingcon=0
time=0
set=0
delay=0
delaycon=0
dusttimer=0
attack=0
scaleX = 1


So whenever my character was facing right, every other key was blocked.. 'Z' for example, it stands for punch, 'X' for kick..etc.. But if I would turn left, they would work (they would change sprite on left with no problem at all) .im sure you get the picture.


As for the 'Z' Code ( sprite changing )

Keyboard press Z

if sprite_index = stand_left_right
{
    sprite_index = s_left_right;
    alarm[0] = 60;
}


image_speed = 0.5


Alarm 0 event

sprite_index = stand_left_right


Thats about it. Ive been using the same code for other games that did not have the acceleration - deceleration effect like mine, and it worked.
(Im talking about sprite changing or 'Z' event)

Thanks mate!

Edited by OzzyEx, 12 February 2012 - 09:34 AM.

  • 0

#5 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2300 posts
  • Version:GM7

Posted 12 February 2012 - 09:41 AM

Well I'm a bit confused, given the code in the Z key, you should NEVER be able to punch after moving in either direction, as there is never any code to revert back to

sprite_index = stand_left_right

So looks lik eyou have more code to post :P

Why is that even a condition anyways? No punching mid-running?

Edited by greep, 12 February 2012 - 09:46 AM.

  • 0

#6 OzzyEx

OzzyEx

    GMC Member

  • GMC Member
  • 151 posts
  • Version:GM8

Posted 12 February 2012 - 09:46 AM

Okay, how about I upload my gmk so you can see better? Its 2,5mb file. What do you say?
  • 0

#7 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2300 posts
  • Version:GM7

Posted 12 February 2012 - 09:47 AM

Told you, don't have GM8 :) But upload it anyways, someone else can figure it out most likely.
  • 0

#8 OzzyEx

OzzyEx

    GMC Member

  • GMC Member
  • 151 posts
  • Version:GM8

Posted 12 February 2012 - 09:48 AM

Ah right.. Alright then, ill post the whole code. Gimme 3mins
  • 0

#9 OzzyEx

OzzyEx

    GMC Member

  • GMC Member
  • 151 posts
  • Version:GM8

Posted 12 February 2012 - 09:56 AM

PLAYER OBJECT:

CREATE EVENT

sprite_index = stand_left_right;
image_index = 0;
image_speed = 0.4;

walkingcon=0
time=0
set=0
delay=0
delaycon=0
dusttimer=0
attack=0
scaleX = 1


ALARM 0

sprite_index = stand_left_right

STEP EVENT

if(walkingcon=2)
time=time+1



if(attack=0)
{
if(set=0)
{
if(time/5 && walkingcon=2)
 {
hspeed=hspeed+0.1
 }
if (hspeed>0.2)
 {
walkingcon=0
sprite_index = stand_left_right
image_xscale = scaleX
image_speed = 0.1
hspeed=0
time=0
 }
}
if(set=1)
{
if(time/5 && walkingcon=2)
 {
hspeed=hspeed-0.1
 }

if (hspeed<0.2)
 {
walkingcon=0
sprite_index = stand_left_right
image_xscale = scaleX
image_speed = 0.1
hspeed=0
time=0
 }
}
}

KEYBOARD EVENT LEFT

if keyboard_check(vk_right) then exit
scaleX = -1
if(attack=0)
if(set=0)
{
time=time+1
if(time/5 && time<50)
{
hspeed=hspeed-0.1
image_speed=image_speed+0.0025
}
}
if(delaycon=1 && set=0 && dusttimer=0)
{

if not(walkingcon=1)
delay=delay+1

sprite_index = Switch
image_xscale = -scaleX
if(delay>5 && delay<10)
{
image_xscale = scaleX
}
if(delay>10){
hspeed=0
walkingcon=1
time=1
set=1
delay=0
hspeed=4
sprite_index = run_Left_right
image_xscale = -scaleX
image_speed=0.05;
delaycon=0
}
}

KEYBOARD EVENT RIGHT

if keyboard_check(vk_left) then exit
scaleX = 1
if(attack=0)
if(set=1)
{
time=time+1
if(time/5 && time<50)
{
hspeed=hspeed+0.1
image_speed=image_speed+0.0025
}
}

if(delaycon=1 && set=0 && dusttimer=0)
{

if not(walkingcon=1)
delay=delay+1

sprite_index = Switch
image_xscale = scaleX
if(delay>5 && delay<10)
{
image_xscale = scaleX
}
if(delay>10){
hspeed=0
walkingcon=1
time=1
set=1
delay=0
hspeed=4
sprite_index = run_Left_right
image_xscale = scaleX
image_speed=0.05;
delaycon=0
}
}

KEYBOARD PRESS LEFT

if walkingcon != 0 then exit
if delay != 0 then exit
if keyboard_check(vk_right) then exit
if(attack=0)
if(hspeed=0)
if not(keyboard_check(vk_right))
if not(walkingcon=2)
{
walkingcon=1
time=1
set=0
hspeed=-2
sprite_index = run_Left_right
image_xscale = scaleX
image_speed=0.05;
}

delay=0

if(hspeed>-0.2)
if(walkingcon=2)
{
delaycon=1
}



if(attack=0)
if(set=0)
{
time=time+1
if(time/5 && time<50)
{
hspeed=hspeed-0.1
image_speed=image_speed+0.0025
}
}
scaleX = -1


KEYBOARD PRESS RIGHT

if walkingcon != 0 then exit
if delay != 0 then exit
if keyboard_check(vk_left) then exit
if(attack=0)
if(hspeed=0)
if not(keyboard_check(vk_left))
if not(walkingcon=2)
{
walkingcon=1
time=1
set=1
hspeed=2
sprite_index = run_Left_right
image_xscale = scaleX
image_speed=0.05;
}

delay=0

if(hspeed<0.2)
if(walkingcon=2)
{
delaycon=1
}

scaleX = 1


KEYBOARD PRESS Z


its just a sprite changing action.. simple as DnD


KEYBOARD RELEASE LEFT


if(attack=0)
if(set=0)
{
sprite_index = Slowdown_left_right
image_speed=0.2;
image_xscale = scaleX
walkingcon=2
hspeed=hspeed+2
}


KEYBOARD RELEASE RIGHT


if(attack=0)
if(set=1)
{
sprite_index = Slowdown_left_right
image_speed=0.2;
image_xscale = scaleX
walkingcon=2
hspeed=hspeed-2
}



Thats it. That is the entire code of my character.
  • 0

#10 OzzyEx

OzzyEx

    GMC Member

  • GMC Member
  • 151 posts
  • Version:GM8

Posted 12 February 2012 - 09:58 AM

Well I'm a bit confused, given the code in the Z key, you should NEVER be able to punch after moving in either direction, as there is never any code to revert back to

sprite_index = stand_left_right

So looks lik eyou have more code to post :P

Why is that even a condition anyways? No punching mid-running?


theres an alarm as u can see
  • 0

#11 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2300 posts
  • Version:GM7

Posted 12 February 2012 - 10:08 AM

Hrm... I'm guessing the problem is the ordering of the sprite changing or somerthing, this is usually a problem where sprite conditions are made whn there's code out of step event... if that's the entire code of the character, do you think you could move everything into the step event? This will be better in the long term anyways

Example:

if (keyboard_check(vk_right))
{
your entire right key check code
}
if (keyboard_check(vk_left))
{
your entire left key check code
}
if (keyboard_check_pressed(vk_right))
{
your entire right key pressed check code
}
if (keyboard_check_pressed(vk_left))
{
your entire left key pressed check code
}

your step code

if (keyboard_check_pressed(ord('Z'))
{
your z code
}

This may or may resolve it immediately, but you will definately want this anyways. While you do that, I'll be looking at the code some more.

Edit: Shoot, that won't work because of your "exit"s. Well it should ve really easy to write it without them.

Edited by greep, 12 February 2012 - 10:10 AM.

  • 0

#12 OzzyEx

OzzyEx

    GMC Member

  • GMC Member
  • 151 posts
  • Version:GM8

Posted 12 February 2012 - 10:11 AM

Alright, let me try with your idea.
  • 0

#13 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2300 posts
  • Version:GM7

Posted 12 February 2012 - 10:23 AM

Also, take out the sprite condition for you code, just to test it out. So attack no matter what you do. Also, if it does work, try replacing the sprite condition with if (walkingcon = 0). This code is really hard to read, so I'll just try generic troubleshooting :whistle:

Edit: Also, in the step event, I see an

if attack = 0

and yet, your z key didn't seem to have an attack = 1. I.e., your step event is overriding your punch sprite. I suspect there is still code you are not showing :verymad:

Edited by greep, 12 February 2012 - 10:25 AM.

  • 0

#14 OzzyEx

OzzyEx

    GMC Member

  • GMC Member
  • 151 posts
  • Version:GM8

Posted 12 February 2012 - 10:25 AM

Its funny because now if I was facing left and pressed Z, the character would spin the whole animation right. But if I was facing right and pressed Z, it would do maybe the first and second image of the sprite. But it WOULD spin it through all images if I was holding the button (Z).

Dang...


EDIT: My exits are very important because they prevent my character from a bug in movement.
EDIT 2: I did try without them, issue is still the same.

Edited by OzzyEx, 12 February 2012 - 10:28 AM.

  • 0

#15 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2300 posts
  • Version:GM7

Posted 12 February 2012 - 10:29 AM

Yeah okay try putting attack = 1 in your z key and putting attack = 0 in your alarm0
  • 0

#16 OzzyEx

OzzyEx

    GMC Member

  • GMC Member
  • 151 posts
  • Version:GM8

Posted 12 February 2012 - 10:47 AM

Nothing,its not working.. Though I tried to delete the whole acceleration - deceleration effect and use the constant speed (basic movement settings) and it worked. So I assume my code isn't compatible with what im trying to do since it was an improvisation of mine.

Do you have any other easier solutions for the acceleration - deceleration effect?
Thanks!
  • 0

#17 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2300 posts
  • Version:GM7

Posted 12 February 2012 - 10:50 AM

Not particularly. Hrm... if deceleration and acceleration is causing the problem, could you repost the code with it commented out (assuming commenting out the code will make it work)? It'll probably be really easy to figure out then.
  • 0

#18 OzzyEx

OzzyEx

    GMC Member

  • GMC Member
  • 151 posts
  • Version:GM8

Posted 12 February 2012 - 10:56 AM

Im not sure if it was AnD. What I did is, I just deleted every keypress event and the thing in step which i provided before.
So I made some basic movement system:

Keyboard event left

sprite_index = run_Left_right;
image_index = image_index;
image_speed = 0.4
hspeed = -4
image_xscale = -1
scaleX = -1



keyboard right is pretty much the same except its in +


EDIT: so it worked if i tried the thing with keypress Z

Edited by OzzyEx, 12 February 2012 - 10:57 AM.

  • 0

#19 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2300 posts
  • Version:GM7

Posted 12 February 2012 - 10:59 AM

EDIT: so it worked if i tried the thing with keypress Z


Wait, so problem solved? Or do you just mean the non- deceleration code works?
  • 0

#20 OzzyEx

OzzyEx

    GMC Member

  • GMC Member
  • 151 posts
  • Version:GM8

Posted 12 February 2012 - 11:02 AM

Problem is at half way.. It works now but you see, I need that acceleration - deceleration effect. So im trying to make them work together..
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users