Jump to content


Photo

help with picking up and placing down


  • Please log in to reply
8 replies to this topic

#1 iphoneiv

iphoneiv

    GMC Member

  • New Member
  • 25 posts
  • Version:GM8

Posted 03 March 2012 - 10:38 PM

hellos, i just need a little help with picking up and placing down items

i can pick an item up and put it down, but i can't seem to be able to pick the item up again (the second time)

codes:

item(that i will hold):
step:
Spoiler


Spoiler


Spoiler


press 'Z':
Spoiler





player:
create:
Spoiler


step:
Spoiler


Spoiler


Spoiler


Spoiler


Spoiler


Spoiler


Spoiler



Spoiler



Spoiler


- yes, they are mostly in step event
i'm not all that experienced as you can tell


the way how i want it to be is like in zelda(the way he picks up and places down)
although in zelda games, he throws the item; i want the player to place it in front of him

i'm sorry for the longness and messiness of it all but i was doing all this in a hurry since i'm going somewhere very soon
-btw, if i made any stupid mistakes, please feel free to point them out
(i'm sure there's alot :>, unfortunately)

if there's anyting else that you need o know, jst ask
any pointers/hints would be awesome, thx (edit:just got back :D)

EDIT: also, if there's another waaaaaaaaaaaaaaaaaay easier way to do the same thing i'm trying to do, i'll be glad to hear it ^^
i want to be able to use this code so that i can pick up and drop many items, not just one specific one(not all items at once, but individually)

Edited by iphoneiv, 04 March 2012 - 07:31 PM.

  • 0

#2 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2300 posts
  • Version:GM7

Posted 03 March 2012 - 11:02 PM

Whoo, if you put each block in spoilers with a label before each I'll read it when you get back.
  • 0

#3 iphoneiv

iphoneiv

    GMC Member

  • New Member
  • 25 posts
  • Version:GM8

Posted 04 March 2012 - 01:23 AM

Whoo, if you put each block in spoilers with a label before each I'll read it when you get back.


i'm back, and i've put them in spoiler tags...still pretty long though, me is very sorry :<
hopefully i'll find what's going wrong with this
and btw, thx, ur the only one who replied, lol
(probably because the codes were way too long)
  • 0

#4 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2300 posts
  • Version:GM7

Posted 04 March 2012 - 01:42 AM

Okay, thta's still a lot of code lol. Okay I'll keep reading but in the meantime, I'm guessing one of these variables:

lift=0
carrying=0
liftTimer=12
downTimer=0
putDown=0
ready=1
liftReverse=0
liftRTimer=12


is not what you want at the time you pickup/drop the item. Do some debugging with at runtime by doing this

(in a key press event of some cheat code button)

theCheat = get_string("CHEAT","")
execute_string(theCheat)

and type in the box show_message(string(theNameOfTheVariableYouWantToTest))

For several variables. Chances are one of them is set to true or false or something and you don't want it to be.
  • 0

#5 iphoneiv

iphoneiv

    GMC Member

  • New Member
  • 25 posts
  • Version:GM8

Posted 04 March 2012 - 02:54 AM

Okay, thta's still a lot of code lol. Okay I'll keep reading but in the meantime, I'm guessing one of these variables:

lift=0
carrying=0
liftTimer=12
downTimer=0
putDown=0
ready=1
liftReverse=0
liftRTimer=12


is not what you want at the time you pickup/drop the item. Do some debugging with at runtime by doing this

(in a key press event of some cheat code button)

theCheat = get_string("CHEAT","")
execute_string(theCheat)

and type in the box show_message(string(theNameOfTheVariableYouWantToTest))

For several variables. Chances are one of them is set to true or false or something and you don't want it to be.


> i checked the variable values and such in the debug mode, but apparently the problem doesn't lie in the variables

i tried to constantly pres 'z' while walking all over the item, and i found that i can lift the item sometimes
dunno y tho OnO

- it might have to do with when the chracter creates the item (after the item was deleted)

EDIT: actually, i think it really does have to do with creating them
when i put the instance create x and y to the player's, i can lift them up any time, but if i put the x and y into the player's +15(or something) then it doesnt work
it probably has to be right in the middle of the little boxes of the grid on the map
i just dunno how to place it in the middle and go in front of the player

Edited by iphoneiv, 04 March 2012 - 03:20 AM.

  • 0

#6 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2300 posts
  • Version:GM7

Posted 04 March 2012 - 03:26 AM

Hrm, if it's not the variables. Hrm.. how exactly does scr_checknear work?
  • 0

#7 FoxInABox

FoxInABox

    GMC Member

  • GMC Member
  • 5417 posts
  • Version:GM:Studio

Posted 04 March 2012 - 03:27 AM

may I suggest that you just give all items that can be picked up the same parent item..

and instead of all the code in the item you can delete the item in front and store the object type and sprite in player, so that player just draw it at the rigth place depending on the action.. when placement action is done you create it in front and clear your variables.

instance_create(o_player.x,o_player.y-10,o_46)

o_46.solid=1
o_46.depth=o_player.depth+1
note that writing object_name.variable will affect only the first o_46 that was placed in room, if you want it to affect the created item you will have to get the returned id from instance_create:
ins=instance_create(o_player.x,o_player.y-10,o_46)

ins.solid=1
ins.depth=o_player.depth+1

if you make an array, where the first number is what you are doing and the second is the direction and you use numbers for the directions instead of strings, then your codes could be simplified a bit, for example:

create
face_dir=0; // 0 = rigth, 1 up, 2 left, 3 down
action=0; // what you are doing

a_carry = 0;
a_carry_run = 1;

spr[0,0]=carryL
spr[0,1]=carryU
spr[0,2]=carryR
spr[0,3]=carryD

spr[1,0]=carry_runL
spr[1,1]=carry_runU
spr[1,2]=carry_runR
spr[1,3]=carry_runD

carry speed part of your code
if carrying=1{
  if spd=2{ action=a_carry; }
  if spd=4{ action=a_carry_run; }
}

// then the sprite change
sprite_index=spr[action,face_dir]

if you use a number for the direction, then it is also possible to create the item in the correct direction by just using one line for all directions:
instance_create(o_player.x + 10*( (face_dir=0)-(face_dir=2) ),o_player.y+ 10*( (face_dir=3)-(face_dir=1) ),o_46)

- enjoy ^^
  • 0

#8 iphoneiv

iphoneiv

    GMC Member

  • New Member
  • 25 posts
  • Version:GM8

Posted 04 March 2012 - 03:38 AM

Hrm, if it's not the variables. Hrm.. how exactly does scr_checknear work?


scr_checknear:

var _c;
_c=argument0

if (_c.x=x and _c.y=y+16 and _c.face_dir = "up")
return (1)
if (_c.x=x and _c.y=y-16 and _c.face_dir = "down")
return (1)
if (_c.x=x-16 and _c.y=y and _c.face_dir = "right")
return (1)
if (_c.x=x+16 and _c.y=y and _c.face_dir = "left")
return (1)

return (0)

it must be pretty troublesome to help me, but really, thx!^^



EDIT:
you know, i jst found it!
i changed the instance create's x and y to
o_player.x,o_player.y+16 (the +16 is the number for all the instance_create, but just depending on where you're facing)

and it worked!
thanks for helping, i'm so happy XD

Edited by iphoneiv, 04 March 2012 - 04:29 AM.

  • 0

#9 iphoneiv

iphoneiv

    GMC Member

  • New Member
  • 25 posts
  • Version:GM8

Posted 04 March 2012 - 03:41 AM

may I suggest that you just give all items that can be picked up the same parent item..

and instead of all the code in the item you can delete the item in front and store the object type and sprite in player, so that player just draw it at the rigth place depending on the action.. when placement action is done you create it in front and clear your variables.

instance_create(o_player.x,o_player.y-10,o_46)

o_46.solid=1
o_46.depth=o_player.depth+1
note that writing object_name.variable will affect only the first o_46 that was placed in room, if you want it to affect the created item you will have to get the returned id from instance_create:
ins=instance_create(o_player.x,o_player.y-10,o_46)

ins.solid=1
ins.depth=o_player.depth+1

if you make an array, where the first number is what you are doing and the second is the direction and you use numbers for the directions instead of strings, then your codes could be simplified a bit, for example:

create
face_dir=0; // 0 = rigth, 1 up, 2 left, 3 down
action=0; // what you are doing

a_carry = 0;
a_carry_run = 1;

spr[0,0]=carryL
spr[0,1]=carryU
spr[0,2]=carryR
spr[0,3]=carryD

spr[1,0]=carry_runL
spr[1,1]=carry_runU
spr[1,2]=carry_runR
spr[1,3]=carry_runD

carry speed part of your code
if carrying=1{
  if spd=2{ action=a_carry; }
  if spd=4{ action=a_carry_run; }
}

// then the sprite change
sprite_index=spr[action,face_dir]

if you use a number for the direction, then it is also possible to create the item in the correct direction by just using one line for all directions:
instance_create(o_player.x + 10*( (face_dir=0)-(face_dir=2) ),o_player.y+ 10*( (face_dir=3)-(face_dir=1) ),o_46)

- enjoy ^^



woaaaaaaaaaaahhhhhhhhhhhhhh, so many good ways to make it not clustered and messy!
thanks, i really owe you; you've helped me so many time :D
i'll go try it out
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users