Collectable items in game

THRSTNTHRSTN Member Posts: 178
edited November -1 in Working with GS (Mac)
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

Comments

  • quantumsheepquantumsheep Member Posts: 8,188
    You could make a new variable on the coin prototype called 'collected' - make it a boolean.

    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 :D

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • THRSTNTHRSTN Member Posts: 178
    that totally seemed like it should work but alas it didn't.
    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.
  • butterbeanbutterbean Member Posts: 4,315
    @Thrstn: If the "self.collected" is a local attribute, and you reset the scene, then it will reset the attribute, however, if you make "self.collected" a global attribute instead, when you reset the scene, it shouldn't again reappear, unless you reset the game.

    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?
  • JamesZeppelinJamesZeppelin Member Posts: 1,927
    nevermind .. my bad
  • THRSTNTHRSTN Member Posts: 178
    butterbean
    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?
  • butterbeanbutterbean Member Posts: 4,315
    Oh good point Thrstn, didn't think about that....

    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.
  • THRSTNTHRSTN Member Posts: 178
    no go also. i have it set to a global variable of "collected" and im using change scene to go between scene's but when i return all the coins respawn .

    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.
  • butterbeanbutterbean Member Posts: 4,315
    Hmmmm.. that's interesting, even if you set each variable to each item as a local variable, and do a change scene, it shouldn't reappear

    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....
  • butterbeanbutterbean Member Posts: 4,315
    So I ran a quick test, and you're right, it doesn't work.

    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)
  • THRSTNTHRSTN Member Posts: 178
    ok since my last post i ended up getting rid of the coins and am going with letters so there are 7 letters on each level to collect as opposed to 40 or 50 coins per level as previous. I first tried to make a Boolean att for each item and then saving when they are hit and loading that into another scene that displays each one as the are captured and having a lock icon with the ones not captured,

    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
  • forkliftforklift Member Posts: 386
    The problem is that you're exiting the scene/level, so of course it's going to reset when you go back into it. Instead of destroying all your coins or letters or whatever isn't working now, make the menu 'inside' the scene.
  • THRSTNTHRSTN Member Posts: 178
    no can do
    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
  • THRSTNTHRSTN Member Posts: 178
    HELLS 2 THE YEAH!! I GOT IT WORKING

    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
Sign In or Register to comment.