Jump to content


Photo

wont fire arrows! help!


  • Please log in to reply
11 replies to this topic

#1 bunsareyum :)

bunsareyum :)

    GMC Member

  • New Member
  • 43 posts

Posted 04 July 2010 - 02:09 AM

if weapon=1
{
if sprite_index=spr_char_right
and bowshot=0
    {
    instance_create(x,y,obj_arrow_right)
    bowshot=1
    alarm[0]=40
    }
if sprite_index=spr_char_left
and bowshot=0
    {
    instance_create(x,y,obj_arrow_left)
    bowshot=1
    alarm[0]=40
    }
}

if weapon=0
{
show_message('You have no weapon selected')
}

i have all the variables set up in create event
i have the alarm set up
i have the sprites create and named like that
i have the objects created and named like that

so i just dont get why it wont work! :(
  • 0

#2 Mnementh

Mnementh

    15151

  • Retired Staff
  • 6261 posts
  • Version:GM:Studio

Posted 04 July 2010 - 02:25 AM

So, what actually happens? Nothing?

Add a call to show_message to each of those if statements; whatever messages pop up will give us more information about what is really happening. Also, you might want to run the game in debug mode, and watch the values of weapon and bowshot to make sure they match your expectations.
  • 0

#3 bunsareyum :)

bunsareyum :)

    GMC Member

  • New Member
  • 43 posts

Posted 04 July 2010 - 02:32 AM

if weapon=1
{
if sprite_index=spr_char_right
and bowshot=0
    {
    show_debug_message('hello')
    instance_create(x,y,obj_arrow_right)
    bowshot=1
    alarm[0]=40
    }
if sprite_index=spr_char_left
and bowshot=0
    {
    show_debug_message('hello')
    instance_create(x,y,obj_arrow_left)
    bowshot=1
    alarm[0]=40
    }
}

if weapon=0
{
show_message('You have no weapon selected')
}

that makes it work... seriously.. what am i not getting? :L oh and i watched those expressions and the values said ERROR
  • 0

#4 CRxTRDUDE

CRxTRDUDE

    GMC Member

  • GMC Member
  • 64 posts
  • Version:GM8

Posted 04 July 2010 - 02:39 AM

Hello, what event did you place that code?
  • 0

#5 bunsareyum :)

bunsareyum :)

    GMC Member

  • New Member
  • 43 posts

Posted 04 July 2010 - 02:39 AM

keyboard - spacebar
  • 0

#6 CRxTRDUDE

CRxTRDUDE

    GMC Member

  • GMC Member
  • 64 posts
  • Version:GM8

Posted 04 July 2010 - 02:43 AM

Do you have like a ammunition variable in the game?
  • 0

#7 bunsareyum :)

bunsareyum :)

    GMC Member

  • New Member
  • 43 posts

Posted 04 July 2010 - 02:54 AM

no.. all you have to do is find the bow and equip it.. but now ive found a problem that you dont actually have to find the bow :L you just have to press 1 :S
  • 0

#8 CRxTRDUDE

CRxTRDUDE

    GMC Member

  • GMC Member
  • 64 posts
  • Version:GM8

Posted 04 July 2010 - 07:37 AM

So, I assume that the object "obj_arrow_right & obj_arrow_left" does not move by itself after created.
So, in that case, let's use a switch command here:

IN KEYBOARD / <SPACE>:

switch(weapon){
case 0:
	show_message('You have no weapon selected');
	break;
case 1:
	if sprite_index==spr_char_right
		{
			if floor(random(15))=0 {
    			show_debug_message('player shoots to the right.');
    			new_arrow = instance_create(x+4,y+16,obj_arrow_right);
        		new_arrow.direction = 0;
        		new_arrow.speed = 15;
			}
    		}
	if sprite_index==spr_char_left
    		{
			if floor(random(15))=0 {
    			show_debug_message('player shoots to the left.');
    			new_arrow = instance_create(x+4,y+16,obj_arrow_left);
        		new_arrow.direction = 180;
        		new_arrow.speed = 15;
			}
    		}
	break;
}

You can fine tune the random number value and speed for your needs.
BTW: "if floor(random(15))=0" is equivalent to "Test Chance" Drag and Drop action in GML (Blackrat's DnD Guide is very handy...)

Edited by CRxTRDUDE, 04 July 2010 - 07:40 AM.

  • 0

#9 ramses12

ramses12

    6

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

Posted 04 July 2010 - 07:51 AM

that makes it work... seriously.. what am i not getting? :L oh and i watched those expressions and the values said ERROR

It's because local variables can't be checked in the debug mode without first pointing what instance they belong to. Try adding a character. before any local variable you check. (replace character with you player object's name)
  • 0

#10 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 04 July 2010 - 08:37 AM

so i just dont get why it wont work! :(

Question : when are you destroying the arrow ? Is it possible it gets destroyed as soon as it gets created ?

Suggestion :
Put a simple "show_message('arrow created')" in the create-event of the arrow and see if it pops up.

Put a same kind of message in the destroy-event and see when it pops up.

If neither pops up the arrow does not get crated. If both show in the same step the problem is in the arrow (it gets destroyed too soon)

If only the first pops up the arrow does get created but is not visible. You could, in the arrows draw-event, draw a line from its own coordinates to the center of the screen/View to see where it went.

Hope that helps.
  • 0

#11 bunsareyum :)

bunsareyum :)

    GMC Member

  • New Member
  • 43 posts

Posted 04 July 2010 - 01:21 PM

So, I assume that the object "obj_arrow_right & obj_arrow_left" does not move by itself after created.
So, in that case, let's use a switch command here:

IN KEYBOARD / <SPACE>:

switch(weapon){
case 0:
	show_message('You have no weapon selected');
	break;
case 1:
	if sprite_index==spr_char_right
		{
			if floor(random(15))=0 {
    			show_debug_message('player shoots to the right.');
    			new_arrow = instance_create(x+4,y+16,obj_arrow_right);
        		new_arrow.direction = 0;
        		new_arrow.speed = 15;
			}
    		}
	if sprite_index==spr_char_left
    		{
			if floor(random(15))=0 {
    			show_debug_message('player shoots to the left.');
    			new_arrow = instance_create(x+4,y+16,obj_arrow_left);
        		new_arrow.direction = 180;
        		new_arrow.speed = 15;
			}
    		}
	break;
}

You can fine tune the random number value and speed for your needs.
BTW: "if floor(random(15))=0" is equivalent to "Test Chance" Drag and Drop action in GML (Blackrat's DnD Guide is very handy...)


once created the arrow objects have a speed=4 in their create events (-4 for left) and also an alarm to tell them when to destory themselves.
all the character does is create the arrow when the spacebar has been pressed (and reloading time)

is that what you mean?


that makes it work... seriously.. what am i not getting? :L oh and i watched those expressions and the values said ERROR

It's because local variables can't be checked in the debug mode without first pointing what instance they belong to. Try adding a character. before any local variable you check. (replace character with you player object's name)


there is a global variable to check if the bow is equipable (global.bow)
there is a local variable (in the player object) to check if the bow is equipped (weapon)
there is a local variable (in the player object) to check if the bow is loaded (bowshot)

and i have the strange feeling that ive misunderstood what you said? :L


so i just dont get why it wont work! :(

Question : when are you destroying the arrow ? Is it possible it gets destroyed as soon as it gets created ?

Suggestion :
Put a simple "show_message('arrow created')" in the create-event of the arrow and see if it pops up.

Put a same kind of message in the destroy-event and see when it pops up.

If neither pops up the arrow does not get crated. If both show in the same step the problem is in the arrow (it gets destroyed too soon)

If only the first pops up the arrow does get created but is not visible. You could, in the arrows draw-event, draw a line from its own coordinates to the center of the screen/View to see where it went.

Hope that helps.


well the arrows being created and destroyed work now.. because of the debug message (which i still dont understand how that makes them work) its just the problem that you dont need to collect the bow to make it equipable.. although i think i have an idea why it does that :D

EDIT: nope.. global.bow=1 permanently... even though in the bow object, in its create event is say global.bow=0?

Edited by bunsareyum :), 04 July 2010 - 02:04 PM.

  • 0

#12 CRxTRDUDE

CRxTRDUDE

    GMC Member

  • GMC Member
  • 64 posts
  • Version:GM8

Posted 05 July 2010 - 09:39 AM

once created the arrow objects have a speed=4 in their create events (-4 for left) and also an alarm to tell them when to destory themselves.
all the character does is create the arrow when the spacebar has been pressed (and reloading time)

is that what you mean?


Well, the "direction" defines the direction so you don't need a "-4" for that.

I should assume that you have a wall and enemy objects (very obvious).
So you can use those to destroy the arrow without needing a alarm.

You can even use the Others/ Outside Room event to remove the arrow when its outside the room.
This way it won't be a hassle to your computer memory.

By the way, the "Test Chance" code is used for the character (presuming that it is human, or human-like) because they can be tired sometimes (sore muscles and stuff) so there are times where the arrows are drawn quick and there are other times they are slow. If you want to be realistic then test chance is there, there is another way for that though...


IN YOUR CREATE EVENT:

timing = 0// "timing" makes an external alarm inside the script. For as long as the player holds the <Space> key, "timing" adds up
   	// until it reaches 5.


---------------------------------------------------------------------------------------

IN THE KEYBOARD/<SPACE> EVENT:

switch(weapon){
case 0:
        show_message('You have no weapon selected');
        break;
case 1:
        if sprite_index==spr_char_right
                {
			if timing < 50{
				timing += 1;
			}
                        if timing == 50 {
                        	show_debug_message('player shoots to the right.');
                        	new_arrow = instance_create(x+4,y+16,obj_arrow_right);
                        	new_arrow.direction = 0;
                        	new_arrow.speed = 15;
				timing = 0;
                        }
                }
        if sprite_index==spr_char_left
                {
			if timing < 50{
				timing += 1;
			}
                        if timing == 50 {
                        	show_debug_message('player shoots to the left.');
                        	new_arrow = instance_create(x+4,y+16,obj_arrow_left);
                        	new_arrow.direction = 180;
                        	new_arrow.speed = 15;
				timing = 0;
                        }
                }
        break;
}


Might be unprofessional, but it should work... Now timing can be either > 5 (for slow projectiles) and 5 for fast ones. All it takes is to fine tune the code...

*** EDIT: Fixed the code.

Edited by CRxTRDUDE, 05 July 2010 - 09:59 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users