Setting up a press (B) to open & close object
#21
Posted 03 May 2012 - 05:02 PM
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;
}
#22
Posted 03 May 2012 - 05:26 PM
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
#23
Posted 03 May 2012 - 05:34 PM
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.
#24
Posted 03 May 2012 - 05:37 PM
#25
Posted 03 May 2012 - 05:39 PM
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"
#26
Posted 03 May 2012 - 05:55 PM
#27
Posted 03 May 2012 - 06:00 PM
hmmm this is slowly making sense
#28
Posted 03 May 2012 - 06:04 PM
Now lets continue down the block.. (where would i place to create the obj_bag to load). and close
#29
Posted 03 May 2012 - 06:09 PM
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.
#30
Posted 03 May 2012 - 06:10 PM
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
#31
Posted 03 May 2012 - 06:18 PM
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.
#32
Posted 03 May 2012 - 06:18 PM
if keyboard_check_pressed(ord('B')) with(obj_bag)visible=!visible;and you can disable movement by checking if it is visibleif obj_bag.visible exit; // don't do code below if bag is openremember to keep the code to open/close inventory above the exit code if you use it.. good luck
#33
Posted 03 May 2012 - 09:16 PM
also I'm glad you found your solution if you have a problem drawing the inventory, tell us!
Edited by creators124, 03 May 2012 - 09:17 PM.
#34
Posted 03 May 2012 - 09:30 PM
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
this cuts my scripting of true false statements in half.. very pleased with this outcome.
#35
Posted 03 May 2012 - 09:41 PM
AWESOME!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.. excitingactually... I never did states.. and case files never understood.
this cuts my scripting of true false statements in half.. very pleased with this outcome.
You learned more GML coding!
This is exciting!
Even I learned states and cases!
well I'm just saying need help with drawing your inventory, tell us!
#36
Posted 03 May 2012 - 09:48 PM
Let me know if you can help me figure that out.. ill contact you personally
#37
Posted 03 May 2012 - 09:56 PM
I love helping!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
also not a big fan of coding yet.(because of medicine, I feel woozy
But I'll try my best!
#38
Posted 03 May 2012 - 09:56 PM
but heres for all of us going forward and actually coding with good practices and not regretting it later!
#39
Posted 03 May 2012 - 11:43 PM
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..
#40
Posted 03 May 2012 - 11:57 PM
WOW!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..
this makes me feel awesome!
I'm glad I'm part of this community!
I like felling helpful, main reason I'm here!
also is everything going smoothly with the inventory selection menu?(possibly shop?)
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











