Help using Global Variables

For questions about using Classic.

Post » Sat Mar 06, 2010 4:52 am

I am currently trying to create an inventory system.

I have an inventory image that is in a group that contains a 'on key press' option to pull up the image.

I have a crown item, and when the player sprite collides with it, 1 is added to a global variable called 'Crown'.

I am trying to make it so when you collide with the crown item and 1 is added to the Global Variable 'Crown', the crown will appear in the inventory image, I have been trying to make this work but I can't seem to make any 'if' statements that seem to work. Using the 'Compare' values doesn't seem to work for me either. If anyone can point me to a tutorial or page that can explain this sort of problem I would appreciate it. I have never really worked with code before, so I am unsure on some processes.

Sorry for the strange layout of the message, I am tired!

Peace!


B
8
S
1
G
2
Posts: 79
Reputation: 1,108

Post » Sat Mar 06, 2010 5:05 am

showus the code
B
16
S
10
G
5
Posts: 255
Reputation: 3,934

Post » Sat Mar 06, 2010 5:07 am

I'm not sure what kind of inventory you are making or how you want it to work. Code would help. Heck, you could even make a picture of how you want it to look to help too.
B
2
S
2
G
2
Posts: 372
Reputation: 1,794

Post » Sat Mar 06, 2010 5:17 am

Code added, sorry about that.

What the inventory looks like doesn't matter to me right now. It's just a gradient image that comes up which will have images of items appear on it as you receive them. For example:

B
8
S
1
G
2
Posts: 79
Reputation: 1,108

Post » Sat Mar 06, 2010 5:48 am

When you pick up an item is it always going to be in the same spot in the inventory? Like, if you pick up a crown later in the game, will it put it in that same spot or can that spot be used by something else? I'm trying to determine how dynamic you need your inventory to be.
B
2
S
2
G
2
Posts: 372
Reputation: 1,794

Post » Sat Mar 06, 2010 5:54 am

[quote="Mr Wolf":3st64awt]When you pick up an item is it always going to be in the same spot in the inventory? Like, if you pick up a crown later in the game, will it put it in that same spot or can that spot be used by something else? I'm trying to determine how dynamic you need your inventory to be.[/quote:3st64awt]

Not very dynamic, it will appear in the same spot all the time. I will probably have a silhouette of the item in the inventory and just fill it in with the item when you get it.
B
8
S
1
G
2
Posts: 79
Reputation: 1,108

Post » Sat Mar 06, 2010 6:13 am

[quote="varr":17sn4ia4][quote="Mr Wolf":17sn4ia4]When you pick up an item is it always going to be in the same spot in the inventory? Like, if you pick up a crown later in the game, will it put it in that same spot or can that spot be used by something else? I'm trying to determine how dynamic you need your inventory to be.[/quote:17sn4ia4]

Not very dynamic, it will appear in the same spot all the time. I will probably have a silhouette of the item in the inventory and just fill it in with the item when you get it.[/quote:17sn4ia4]
GREAT! That is MUCH easier. :)

As for your code, it looks like it would set the crown global variable to 1, but then the global variable would only tell it to make your INVENTORY visible. The "Crown Equal to 1" event is using your Inventory Gradient.

I'm not exactly sure how you want your Inventory to open, but here's something:

Make a new layer and name it "Inventory." Create a new Global Value named "showInventory" or whatever will help your remember what it does. You should create an event saying that if "showInventory" = 1, set Layer "Inventory" Visible. Then use Else or If "showInventory" = 0 to have it set Layer "Inventory" to Invisible. That layer should hold your gradient background for your inventory menu and whatever items go in your inventory.

Next, change your "Crown = 1" event to use the actual Crown Sprite instead of the Inventory. If you want your inventory to open when you pause the game, you can use Time Scale and stuff along with Enter Key is pressed (Mouse/Keyboard Object).

--
That isn't a complete tutorial or anything, but you can search around the forum more for the different parts of that (pausing, etc). I'm sure someone else will come along and help too, lol. I'm too tired.
B
2
S
2
G
2
Posts: 372
Reputation: 1,794

Post » Sat Mar 06, 2010 6:34 am

[quote="Mr Wolf":1z2jpwgo][quote="varr":1z2jpwgo][quote="Mr Wolf":1z2jpwgo]When you pick up an item is it always going to be in the same spot in the inventory? Like, if you pick up a crown later in the game, will it put it in that same spot or can that spot be used by something else? I'm trying to determine how dynamic you need your inventory to be.[/quote:1z2jpwgo]

Not very dynamic, it will appear in the same spot all the time. I will probably have a silhouette of the item in the inventory and just fill it in with the item when you get it.[/quote:1z2jpwgo]
GREAT! That is MUCH easier. :)

As for your code, it looks like it would set the crown global variable to 1, but then the global variable would only tell it to make your INVENTORY visible. The "Crown Equal to 1" event is using your Inventory Gradient.

I'm not exactly sure how you want your Inventory to open, but here's something:

Make a new layer and name it "Inventory." Create a new Global Value named "showInventory" or whatever will help your remember what it does. You should create an event saying that if "showInventory" = 1, set Layer "Inventory" Visible. Then use Else or If "showInventory" = 0 to have it set Layer "Inventory" to Invisible. That layer should hold your gradient background for your inventory menu and whatever items go in your inventory.

Next, change your "Crown = 1" event to use the actual Crown Sprite instead of the Inventory. If you want your inventory to open when you pause the game, you can use Time Scale and stuff along with Enter Key is pressed (Mouse/Keyboard Object).

--
That isn't a complete tutorial or anything, but you can search around the forum more for the different parts of that (pausing, etc). I'm sure someone else will come along and help too, lol. I'm too tired.[/quote:1z2jpwgo]


Awesome! Thanks a bunch. I've gotten the system partially working and tomorrow I will elaborate on it and post in this thread if any more problems arise. Thanks again!
B
8
S
1
G
2
Posts: 79
Reputation: 1,108

Post » Mon Mar 08, 2010 6:12 am

One more problem I encountered.

If the inventory screen is visible and you pick up the crown, it will not show until you close and open the inventory again. I am still figuring out how to fix this but any fresh eyes will help! Thanks again.

B
8
S
1
G
2
Posts: 79
Reputation: 1,108

Post » Mon Mar 08, 2010 9:34 am

Oye again, just another quick problem I am having a hard time resolving:

I need to have the controls set up so when you press '1' it disables 'Ghostcrown' and sets everything it disabled back to enabled as well as enabling 'Ghostcrown' at the end so you can repeat. The problem I come to is that when '1' is pressed, it both activates and de-activates everything at once.



B
8
S
1
G
2
Posts: 79
Reputation: 1,108

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests