Page 1 of 1

Storing and collecting items

PostPosted: Mon Sep 19, 2011 1:38 pm
by beginnerirvaz
Ive looked on the forum for a tutorial that can describe how to add items to platformer. Coins, extra lives etc and also store them. Does anybody no of such a tutorial?

Thanks

Re: Storing and collecting items

PostPosted: Mon Sep 19, 2011 10:35 pm
by skydereign
Well, there isn't a tutorial on exactly that, but it sounds like you just want to use saveVars and loadVars. What you would do is have an array, and each sub of the array will hold a different item. When you get an item, you increase the proper sub, and you can save and load this if you want. But if you want to save the spawning of these items, so for example when you replay the level the coins and powerups that you already got won't appear, then you'll have either have a giant array, or similar.

Re: Storing and collecting items

PostPosted: Tue Sep 20, 2011 11:22 pm
by beginnerirvaz
Hey thanks for the reply sorry I haven't replied sooner I didn't realise

Thats great advice thanks for that, I've been able to add a few items for restoring health. I followed the demo in GE for counting objects. So I have a health restore item that when you collide with it it shows in a count. from this count I would like to be able to left click and depending on what the hp value for that item it will increment the players hp count. Forgive me if this doesn't make any sense.

Here is my code -

I have a actor variable called hp

player actor

player - create actor - script

Code: Select all
hp=100;


player - collision - any side of enemy - script

Code: Select all
hp-=1;
if(hp<=0)
{
DestroyActor("Event Actor");
}


hpCount actor

hpCount - draw actor - script

Code: Select all
textNumber = player.hp;



Any ideas on how to get this to work?

Thanks

Re: Storing and collecting items

PostPosted: Tue Sep 20, 2011 11:38 pm
by beginnerirvaz
I should of added I have a health item when collected shows in a health item count on screen. I have a small box background behind this count, its the box I would like to click and say I had 1 of these items and its worth 10hp this would be added to the players hp and hp count. Apologies again if this isn't making any sense.

Re: Storing and collecting items

PostPosted: Wed Sep 21, 2011 1:13 am
by skydereign
Well, you just need to increase hp at different levels for each click. So, either you have different actors that have the mouse button down event, but each one has a different augment, or you have a variable that determines how much to increase the hp by that you set at some point.
item_display_0 -> Mouse Button Down -> Script Editor
Code: Select all
player.hp+=10; // switch for other items

Still not entirely sure of your setup, but from the sounds of it one of those two systems should work.

Re: Storing and collecting items

PostPosted: Wed Sep 21, 2011 12:47 pm
by beginnerirvaz
Thanks skydereign

That worked great but I need it to only allow you to click and add 10hp if you have collected a health restore item. So if the count shows 1, I could click once and my hp is increased by the chosen value. If it shows 0 you can't click etc.

Re: Storing and collecting items

PostPosted: Wed Sep 21, 2011 10:19 pm
by skydereign
Well then just do this.
item_display_0 -> Mouse Button Down -> Script Editor
Code: Select all
player.hp+=10*(ActorCount("item")==1);

Re: Storing and collecting items

PostPosted: Wed Sep 21, 2011 10:34 pm
by Jagmaster
I never think of using actorcount instead of a var. Then I end up with a bunch of vars that I can't get rid of very easily.

I was just going to post my method which is longer and sloppier, but then Sky beat me to it with a better way (which made me remember about actorcount and showed me a new way to use it) :P

Create a global var -> HPenable

mousedown: Hpenable=1;

Other mousedown : hp+=10*HPenable.

Anyway, that will work too. :P
I guess...