Problem with experimental game.

Hi, this one is weird,

Basicly I’m trying to do something with the same mechanics of spacestation 13, I decided to do a small test to see if something like an ss13 remake is doable using gdevelop.

Basicly getting a player to smoke a cigarette, unfortunately, a few variables aren’t getting updated as they should, I can’t see why. So I’m uploading the project in hopes someone can take a look at it.

Instructions:

( squares at the left side of the GUI are, actually, your hands)
Move the player using the arrows near the table.
Click on the cigarette pack to pick it up
Press the C key in order to switch hands.
click on the cigarette pack that’s on your right hand ( on the GUI)
now click on the cigarette pack again with your left hand still active ( on the GUI again)
now try to get the cigarette back from the pack, you can’t.

If you check on the debugger, the variables"leftbusy" and “leftcig” of guy, aren’t getting updated as they should.
The variable “cigamount” of both cigbox and cigboxgui, aren’t getting updated as they should.

I looked at the events and debugged the thing tons of times, but I still can’t seem to see what’s wrong. Let me know if you need any additional information, tips on how to do all of this the “right way” are also appreciated.

LINK to the project file and sprites:

https://filehost.net/ae8303d10fb33623

Thanks for reading!

UPDATE: looks like the variables are changed to what they should for a split second and then they go back to 1, maybe the events are, for some reason, running at the same time? I can’t really tell.

I take a look at your project and I’m not entirely sure of the problem, but…

  1. I think it’s a problem with the events flow. You don’t even have a single subevent! So, all events are running at the same level and when a variable return it’s status to default the current “mouse click” still fires the previous condition again. So, check your algorithm flow, timers will not do the magic if everything is at the same level, use sub-events.

  2. Your system is too rigid. You can use variables in a smarter way. For example: three variables are enoguh to manage the hands: one that holds a value representing the selected hand, and two to set wich item is in each hand (example: lefthand=0, there is nothing in the left hand, lefthand=1, can be there’s a cigarrette box in the left hand, righthand=2, can be there’s a… let’s say a screwdriver in the right hand, etc… so, you can use a list of codes, one for each item, instead of making a variable for ea ch item… that will be a huge and unefficient work to do).

  3. Items are always flickering because the constantly “move towards a point” event. Put an invisible object in the guy hands, when the objects touch it then put the object at the center point in the hand and stop moving it.

Hope some of this can help.

Your post just literally flew my toupe off , I’m not sure how sub-events work, so that’s why everything was working so bad in the first place, I don’t even know what sub-evetns do, I’ll try to implement sub-events, maybe there’s a tutorial somewhere.

Regarding the variables, I’m not sure if I’m too stupid or if you’re a genius, that’s basicly 1000% better than the way I was doing it, which now, it seems like the most stupid thing I ever heard of. I’ll re-do the whole thing applying this, which is great.

I’ll also take a look at this, keep in mind i need the object to stay on the guy’s hands though.

Thanks for taking the time to check this mess I made and helping me do it the right way, really, I’ll post results tonight!.

You aren’t stupid boy, you’re constantly learning, like everyone else.

A sub event allows you to structure your code in such a way that you can add additional conditions for some but not all actions.

For example, if your main event has conditions

If A, B then Do 1, 2

and then you have a sub-event with condition C and action 3

That means if A & B (whatever those are) are both true, then actions 1 and 2 will always run. However, action 3 will ONLY run if A, B AND C are all true, and it runs after action 1 & 2 are run.

So, to try to give an example, you might use a main event to determine some high level status in the game, like checking a status variable that indicates, I don’t know, the player is pressing an arrow key to move, and the action might be to apply a force in the direction the key press indicates. You might then have a sub-event that checks if the player is also drunk, and if a player is thus both moving AND drunk, apply a second force at 1/2 the magnitude in a randomized direction. Thus they stumble around instead of having full control of movement.

I tried what you guys suggested to no avail, I must be doing it wrong, I understand the concept but maybe I’m just unable to apply it to what I’m trying to do.

Added some sub events but I can’t even get the first parts to work correctly.

https://filehost.net/a65285752abf3069

It looks like it’s working but everything happens at the same time.

Got the cigbox to appear in the GUI, right now you have:

[code]If click on cigbox >> Create cigboxgui

If click on table >> Delete cigboxgui[/code]

The problem is that the cigbox is on the table, when you click on the cigbox you’re also clicking the table (GD creates and deletes the cigboxgui in the same frame), I’ve added the condition “Cursor is NOT over cigbox” in the event that deletes the cigboxgui:

[code]If click on cigbox >> Create cigboxgui

If click on table and NOT click on cigbox >> Delete cigboxgui[/code]

Also, I guess it’s because you’re starting, but when you have a lot of “repeated” events:


Probably there’s a shorter way to write the same, note that amount + animation = 6 (for example when the variable amount is 4, the animation number is 2, 4 + 2 = 6), so animation = 6 - amount:

Hi again!

First of all, I made this with the first version of the project you uploaded. I made 4 changes:
1 - I simplified the cigbox’s animation management as suggested by Lizard-13.
2 - I replaced “left mouse button pressed” by “left mouse button released” conditions. I recomend doing this for all mouse clicks interactions that needs to be executed once. Use “mouse pressed conditions” if you wanna have continious actions.

3 - I made a debug display with a text object so you can see the variables values in real time. see the last event.
4 - I left the timer and put its value to zero. You dont need it anymore, unless you really want a cooldown before we can put the cigarete back. Otherwise you can delete it.
Here is the link: https://www.dropbox.com/s/zdt9uggptz5g8oz/robert20%20-%20spacestation.7z?dl=0
well I hope that helps you once again and good continuation :wink:

P.-S. I made a few more tests and the problem is not solved. The problem here is that even if we use sub-events, GDevelop still reads all of them every frame. I am keeping simplifying the events and at the same time continue seeking for the solution.

ok so I worked a little more on the project and finally come up with a solution. First, let me give some explanations.
Doing the following in GD doesn’t work:

if ( player click on cbox ) {
   if ( var left_cig of guy = 0 ) { do = 1 to var left_cig of guy; and do + 1 to var cig_amount of cbox; }
   if ( var left_cig of guy = 1 ) { do = 0 to var left_cig of guy; and do - 1 to var  cig_amount of cbox; }
}

What is happening here is that GD reads the first sub-event and verify its condition. Since the variable left_cig is equal to 0, GD executes the actions and makes the variable left_cig equal to 1. However, right after that, GD reads the second sub-event during the same frame and verify its condition. At this point, the second sub-event’s condition is true since we just set left_cig variable’s value to 1. Then GD executes its actions and set the variable’s value back to 0. Doing it that way in GD just result in the sub-events cancelling each other.

The good way to do is as following:

if ( player click on cbox ) {
   do + 1 to var left_cig of guy ;
   if ( var left_cig of guy > 1 ) { do = 0 to var left_cig of guy; }
   if ( var left_cig of guy = 0 ) { do + 1 to var cig_amount of cbox; }
   if ( var left_cig of guy = 1 ) { do - 1 to var  cig_amount of cbox; }
}

I made other changes that you will find certainly useful but I leave you the care to discover them. I also updated the link in the precedent post so you can download the zip file and look at the changes.

I tried it, and it’s exactly what I needed, Can’t thank you enough for taking the time to check the problem and find a solution, I’m now going to read through your posts 20 times so I can get the idea, I guess I can just keep adding more things using this same solution.