Collectable items in game
THRSTN
Member Posts: 178
hi all I'm working on a game with collectable items (think like coins in sonic or Mario bros.) and I'm having a problem if the player exits the level to goto the menu screen or options screen when they return to the level theyr score is the same but the object respawns along with the level giving them the ability to double up on points. How can I stop this. I know there has to be a couple ways to do this I'm just looking for the best way to deal with it considering there's anywhere from 40 to 60 of these actors on the screen. All the same actor just multiple instances of them.
Thanks
THRSTN
Thanks
THRSTN
Comments
Then, when player collides with coin, change collected to true.
At the top of the rule set for your coin, have a rule that says:
If self.collected = true, destroy actor.
That way, when a scene is reset, any coins that have already been collected will destroy themselves.
There are probably better ways, but off the top of my head, that should work!
Hope it helps,
QS
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io
i placed an attribute inside the coin called collected and set it to false
already had a rule in place there that when actor collides with player
Change attribute game.Score to game.Score +1
and
Change attribute self.collected to true
and
Destroy actor
now
i have
Rule:
attribute self.collected is true
destroy actor
Rule:
when actor collides with player
change attribute game.Score to game.Score+1
change attribute self.collected to true
and when i leave and return to the screen the coins reappear.
don't understand whats goin wrong cause the player actor has no rules regarding the coin
and i know that collected is being triggered cause it is destroying the coins on contact.
I tried saving the attribute and loading it when the scene starts but after the first run thru when i came back to the scene it destroyed all the coins not just the ones collected in the first go.
So go into the global attributes section, make an attribute called "Item Collected" or something like that, and see if that works.
Let me know if this works k?
i changed over collected to a global variable but the problem with that is once 1 coin is hit now they all disappear. this would work if there weren't like 20 instances of the same actor on stage and im not sure but i didnt think you could call a global attribute to self. can you?
That's a tough one, and I would think the best way in your situation is to instead of doing a "reset scene" do a change scene back to that level if the player loses, but make sure to reset all the variables that need to be reset, and stick to doing self.attributes for the coins (local attributes)
I think that would be the best solution.
So when you do the "Change scene" it shouldn't reset the local variables, so any coins that were collected should not reappear upon change scene.
Make sure when you do a change scene you must reset all local and global attributes that need resetting ie: Timers, etc (except the coins or collectables), and that should work best.
I'm seriously debating on changing the gameplay to be a special 6 characters to collect thru each level rather than the 40 or so i have now and set each as an attribute just for sanity sake.
Try this rule in each coin:
Create a variable: self.collected in each coin
When all are true:
When overlaps or collides with player AND When self.variable collected is false
Change attribute, self.collected to true
Change Score: +1 (Or whatever it is)
And that should work, and if you change scenes, it should not reappear, but I'll try testing it in one of my games perhaps....
The only way to do it is one of two ways:
Create a global game attribute for each item named "self.collected"
OR
You could create one global game attribute for the items, as integer, and change it by 1 each time an item is collected BUT this would only work if the player could not skip over the items, and they would have to be collected in a sequence.
UNLESS, you want to randomize placement of the coins or items, then it might work, so when the level starts over, and they collected 3 out of 5 coins, 3 of those would be gone, but the other 2 could be somewhere else each time the level restarts, which could make it more interesting.
If you do it that way, then you could stick with one global game attribute, call it coins collected (as an integer global attribute)
This did not work for some reason because i was unable to save and load the Boolean att to the other screen. (i have twenty levels so that's 120 Boolean att i have to go in and erase now yay.)
next i thought what if i had an integer att called Level1Letters set to 0 then when player collides
game.Level1Letters +1 .I save game.Level1Letters then load that on the reveal letters scene into an actor who has the rule if att game.Level1Letters is >0 reveal "A" then another actor >1 reveal "B" and so on.
This worked.
The only problem with it is the same problem i had when i started this topic. I have the "Letter" Actor as 1 actor that animates the word so i don't need 6 other actors. When it collides with the player its destroyed but when i leave the scene and return it respawns along with the 6 other instances of it in the scene and allows the player to collide with it and adds +1 to game.Level1Letters. when game.Level1Letters = 7 they destroy themselves.
i cant seem to figure out how to get the Letters collected to stay gone when the scene returns from the main menu or level select screen.I even tried using the Boolean att i made and saving and loading them per actor but that didn't work either.
has anyone else had a problem saving and loading Boolean attributes?
and how do i correct this?
Thanks for your help
THRSTN
i have 20 levels and around 7 menu scenes all on they're own scene.
there has to be a way to do this rather than having it all on one giant scene together
i ended up using the boolean att i created and making a seperate actor the load actor was able to get them to destroy themselves on returning to the scene. AWESOME
thanks everyone for your help
THRSTN