GML how to make the character get items from the scenario


I'm creating a platform game, and I don't know how to make the character take an item and capture it permanently or even for a certain time, can someone help me?


That's a pretty big question with many ways to do it and its going to be based on the game you want to make. If we are talking about running down a hall and finding a gun or a sword it could be as simple as a collision event with a global variable. Create a Control object that has a global.hassword = 0;. When we touch the sword global.hassword = 1; ... Now our player when ever we use our attack key checks to see if global.hassword = 1 {run attack code} or something like that

You can do this for a small tool bar also if you know what all your items are and what tool bar slot will be what item. Almost like a Zelda like thing. If global.hassword = 1 && global.selectedtoolslot = (1,2 or what ever you are going to use) and we use the attack key run attack code. You will need to mess with it and know what your items will be but it could work for something simple where you only have a few items... Sword cuts the long grass and holy water makes the wall of zombies run away. The game has TWO items and that's all we will need.

On the other hand if you want an full on backpack with slots that you can pick up items and drag them around and put armor on your hero and arrange your tool bar and the like you will need a data structure. Its something to learn and I would go watch some videos on you tube about it OR go pay like 5 to 20$ on the marketplace for GMS and adjust someones item system to your own game, saves a lot of time, you learn a lot and keeps your project rolling

Anywho- I'm not very good at coding or GMS but no one said anything and I thought I would offer what little I know : ) - global variables ... I think that's what you are looking for.


agree with SkyKnight there is alot of ways to handle this.. what have you tried so far?

basic flow could be something as simple as this..
initialize held item variable
collision of player and item
destroy item
change held item variable
draw item on player's position


you simply need a variable that is either 0 or 1. you can change that variable at any time. the more important thing is to structure your code well.