Jump to content


Photo

Setting up a press (B) to open & close object


  • Please log in to reply
43 replies to this topic

#21 talonstart

talonstart

    Artist

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

Posted 03 May 2012 - 05:02 PM

Im starting like this

i made new project..

I created an object called

obj_controller...

In create event i made your

state = "start" (if this is correct)

i made a step event (pasted your code)
also created object called obj_box

im just testing how this works...

just need the walk through.

I understand you dont wanna write it for me, i wont learn.. I respect that.. but im trying to figure the steps, and how i learn requires heavy attention.. cause i like to break it down how it all works...


this is now in my obj_controller steps (whats first)
switch (state)
{
case "start": {

}; break;
case "running": {

}; break;
case "bag": {

}; break;
case "dead": {

}; break;
default: //put some backup code if your switch statement doesnt work;
}
  • 0

#22 Jack Indie Box

Jack Indie Box

    GMC Member

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

Posted 03 May 2012 - 05:26 PM

no put that state machine in the player object. as thats where the code will run, then you can put movement within the "running" section and all the inventory code inside the "bag"...


if you want another global state machine you should use global.gamestate and put that in the controller with a switch statement, that has menu, start,gameplay, gameover, highscore, restart
but this is not necessary for just programming the gameplay
  • 0

#23 talonstart

talonstart

    Artist

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

Posted 03 May 2012 - 05:34 PM

ah... okay will im scripting this up..

so right now not to worried bout whats in the inventory, but to just open and close the obj_box...

where would the code go for that. using ur mock up.
  • 0

#24 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 03 May 2012 - 05:37 PM

if the player can open it up no matter what (except dying) put it in the character if you want to open it at specific points create an obj_bag that is in the specific places and only accessible through that obj_bag.
  • 0

#25 talonstart

talonstart

    Artist

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

Posted 03 May 2012 - 05:39 PM

create event
state = "start"

steps event (player)

switch (state)
{
    case "start": {
    //put any start up code for the object
    }; break;
    case "running": {
    if keyboard_check(ord('A')) x-=2.8
    if keyboard_check(ord('D')) x+=2.8
    if keyboard_check(ord('W')) y-=2.8
    if keyboard_check(ord('S')) y+=2.8
    }; break;
    case "bag": {
    //put bag code
    }; break;
    case "dead": {
    //put any dead code
    }; break;
    default: //put some backup code if your switch statement doesnt work;
}


tried this out.. upon loading, i placed the object into the room.. w a s d dosnt move.. soo what am i missing here to control the "running"
  • 0

#26 Jack Indie Box

Jack Indie Box

    GMC Member

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

Posted 03 May 2012 - 05:55 PM

you have to transition between the states, you havent told it to change from start to running. if you dont want a start state just change the value to "running" in the create and then test again
  • 2

#27 talonstart

talonstart

    Artist

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

Posted 03 May 2012 - 06:00 PM

ahhh

hmmm this is slowly making sense
  • 0

#28 talonstart

talonstart

    Artist

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

Posted 03 May 2012 - 06:04 PM

okay.. got it, in the start, i just made state = "running" it started that up nicely.

Now lets continue down the block.. (where would i place to create the obj_bag to load). and close
  • 0

#29 talonstart

talonstart

    Artist

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

Posted 03 May 2012 - 06:09 PM

GOT IT :D hahahahahhahah

AWESOME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

switch (state)
{
    case "start": {
    state = "running"
    }; break;
    case "running": {
    if keyboard_check(ord('A')) x-=2.8
    if keyboard_check(ord('D')) x+=2.8
    if keyboard_check(ord('W')) y-=2.8
    if keyboard_check(ord('S')) y+=2.8
    if keyboard_check(ord('B'))
    {
    state = "bag"
    }
    }; break;
    case "bag": {
    instance_create (120,120,obj_box)
    if keyboard_check (ord('B'))
    {
    with obj_box{instance_destroy()}
    state = "running"
    }
    }; break;
    case "dead": {
    //put any dead code
    }; break;
    default: //put some backup code if your switch statement doesnt work;
}

oh yah, and thanks for the keyboard_check_pressed works so much smoother

Edited by talonstart, 03 May 2012 - 06:13 PM.

  • 0

#30 Jack Indie Box

Jack Indie Box

    GMC Member

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

Posted 03 May 2012 - 06:10 PM

lol your still not getting it, you dont need a whole extra object for the bag. this code will allow for it in the player.

when you swap to bag state, you just change the controls and draw the inventory/anything in it. so you need this state machine in the draw event too.

once you have the player drawn in the "running" section of the draw, you can have drawing of the inventory in the "bag". and pressing b should toggle them if you put in the step event

//in running
if keyboard_check_pressed((ord('B')){state="bag";}

//in bag
if keyboard_check_pressed((ord('B')){state="running";}

it should swap and change between the 2 and you should see it
  • 0

#31 talonstart

talonstart

    Artist

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

Posted 03 May 2012 - 06:18 PM

I get what your saying.. but right now, this was what i was looking and is working for me right now.. The inventory object bag.. as i was stating is how i needed it open.. for that object carries vital information.. and things i use.. But i also see that i can just draw the sprite / and the texts / boxes / anything i want to be placed in there. but that wasnt my concern right now..

I'll still play with it.. and probably have more questions.. but right now, you made my object do exactly what i was looking for.. 1 + rep for you my friend Thanks so much.
  • 0

#32 FoxInABox

FoxInABox

    GMC Member

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

Posted 03 May 2012 - 06:18 PM

In case you wanted to know.. your earlier open/close code could be cut down to:
if keyboard_check_pressed(ord('B')) with(obj_bag)visible=!visible;
and you can disable movement by checking if it is visible
if obj_bag.visible exit; // don't do code below if bag is open
remember to keep the code to open/close inventory above the exit code if you use it.. good luck
  • 0

#33 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 03 May 2012 - 09:16 PM

I think you should still do Jack's way since it is more efficient. :D
also I'm glad you found your solution if you have a problem drawing the inventory, tell us! Posted Image

Edited by creators124, 03 May 2012 - 09:17 PM.

  • 0

#34 talonstart

talonstart

    Artist

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

Posted 03 May 2012 - 09:30 PM

Jacks way is def. the direction i'll be heading when i get to that..
right now, not needing too.. i got what i was looking for, and when i get to drawing the (boxes) to collect the items, ill head his way.
i understand it now.. just needed that little push... was like he said, over thinking the situation.. trying to hard for something simple.

but im glad i figured this out.. this is 100% useful for many things now.. exciting :) actually... I never did states.. and case files never understood.
this cuts my scripting of true false statements in half.. very pleased with this outcome.
  • 0

#35 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 03 May 2012 - 09:41 PM

Jacks way is def. the direction i'll be heading when i get to that..
right now, not needing too.. i got what i was looking for, and when i get to drawing the (boxes) to collect the items, ill head his way.
i understand it now.. just needed that little push... was like he said, over thinking the situation.. trying to hard for something simple.

but im glad i figured this out.. this is 100% useful for many things now.. exciting :) actually... I never did states.. and case files never understood.
this cuts my scripting of true false statements in half.. very pleased with this outcome.

AWESOME!
You learned more GML coding! Posted Image
This is exciting!
Even I learned states and cases! :D Posted Image
well I'm just saying need help with drawing your inventory, tell us!Posted Image
  • 0

#36 talonstart

talonstart

    Artist

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

Posted 03 May 2012 - 09:48 PM

well how bout ill contact you when im ready to start scripting how to put the items in to the inventory..
Let me know if you can help me figure that out.. ill contact you personally
  • 0

#37 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 03 May 2012 - 09:56 PM

well how bout ill contact you when im ready to start scripting how to put the items in to the inventory..
Let me know if you can help me figure that out.. ill contact you personally

I love helping!
also not a big fan of coding yet.(because of medicine, I feel woozyPosted Image)
But I'll try my best!Posted Image
  • 0

#38 Jack Indie Box

Jack Indie Box

    GMC Member

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

Posted 03 May 2012 - 09:56 PM

btw, the only reason i knew about states was university :P and i have rarely used them as i am lazy, but it is great coding practice. having coded in game maker since 4.0(self taught ofcourse) i never did use them till 4 years ago and its a hard habbit to break into XD

but heres for all of us going forward and actually coding with good practices and not regretting it later!
  • 0

#39 talonstart

talonstart

    Artist

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

Posted 03 May 2012 - 11:43 PM

Agree'd

I usually scripted in as2.0, But i got a little bug when scripting in as3 and was just so frustrated with there whole concept, and did some research for game engines, came across gamemaker 8.1.
Read about it, and saw it has alot of java / as2 feel to it, Just now i dont gotta script every event to happen like i was in as3.. import this , import that, add this, if that, cross your fingers there talking properly, checking mem leaks.. all became to slow my progress down when starting Nuclear Fallout (nebula shooter).. i been working on for almost 2 years. After getting gm... It worked like a champ for all my games to come. this is a perfect engine.. 2.5d games im into casual gamers.. NF will become a great shooter, (great graphics / effects) all built in 3dsmax, with a little help from a couple of coding buddies, who implanted alot of scripts as well..

Im glad to find a great community and people that are all willing to push and help on another, with proper communication..
  • 0

#40 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 03 May 2012 - 11:57 PM

Agree'd

I usually scripted in as2.0, But i got a little bug when scripting in as3 and was just so frustrated with there whole concept, and did some research for game engines, came across gamemaker 8.1.
Read about it, and saw it has alot of java / as2 feel to it, Just now i dont gotta script every event to happen like i was in as3.. import this , import that, add this, if that, cross your fingers there talking properly, checking mem leaks.. all became to slow my progress down when starting Nuclear Fallout (nebula shooter).. i been working on for almost 2 years. After getting gm... It worked like a champ for all my games to come. this is a perfect engine.. 2.5d games im into casual gamers.. NF will become a great shooter, (great graphics / effects) all built in 3dsmax, with a little help from a couple of coding buddies, who implanted alot of scripts as well..

Im glad to find a great community and people that are all willing to push and help on another, with proper communication..

WOW!
this makes me feel awesome!Posted Image
I'm glad I'm part of this community!Posted Image
I like felling helpful, main reason I'm here!Posted Image
also is everything going smoothly with the inventory selection menu?(possibly shop?)Posted Image
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users