How do I place a random sprite and retrieve it's value?

0 favourites
  • 6 posts
From the Asset Store
It's here!
$4.95 USD
Creepy and nasty horror track. It's terrifying from the beginning till the end. Goosebumps guaranteed
  • Hello Everybody,

    Hi again a question from this newbie.

    I guess the question is asked many times before, but I can't find anything about it.

    This is my problem:

    I want to place 'On Start of Layout' random (on the same X, Y spot in the game) only one sprite, from a collection, stored under the names K00, K01, K02 etc. (say in total about 30 sprites or so).

    I guess I have to store all of them in a family?

    I also want to retrieve (see, use) the Instance Variable 'Value' of each sprite that is shown in the game.

    I can't figure it out. In all Events I tried I had to select one of the sprites by name.

    I can't use the 'Choose (K00, K01, K02)' that one can use on the Action side of the Event Sheet.

    I have the feeling I miss something simple, because nobody asked about it before.

    Or is there a Plugin or Behaviour I should use and don't know about?

    Sorry if it's too obvious, but I can't see the solution myself...

    Many thanks in advance for the help,

    be sure it's very much appreciated.

    Philip

  • Not sure I understand exactly what you want to do.

    But if you make the 30 sprites that you need and add all of them to a family as you mentioned. Then you add a variable to the family itself called "Name" that will make it available for all the 30 sprites. Then you name all the sprites what you want "K00", "K01" etc.

    Then you can select them using that name. Likewise if you want each of them to have a certain value variable you can add a value as well.

    Condition:

    Pick Family.name = "K00" - (Will select all sprites in the family that have this name.)

    Action:

    Set Result = Family.Value - (Will set something called Result to the value of the selected sprite (Family))

    Regarding choose, im not certain if you can do the following as I haven't tried it, and I don't use choose that much.

    Choose (Family.Name = "K00", Family.Name = "K01", etc.)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Dear Nimos,

    Thanks so much for your time to help me, but I feel ashamed to say that it did not help me yet.

    I am trying and trying and can't solve the puzzle yet.

    I have the feeling I want to use a tool that's not in the box (yet).

    But I also have the feeling that the missing tool I can't find is something that is very useful for everybody.

    I guess in many games, game builders want to put a random sprite from a Family (or a list or a folder) of sprites on a certain place (X, Y)

    in their game and also need to know it's Local Variable.

    It could be useful for appearing random all kinds of things on a certain place to make the game more interesting,

    as when every time the same object is showing up.

    And of course the game builder needs to know the local variables of it too.

    But I can't solve this, and again maybe I look over it and there is a simple solution for it.

    But I am afraid I want something simple which is actually very complicated...

    I Thought to choose on the 'Add Event' side: System, 'Pick random Instance'.

    I could choose only one item so I choose Family.

    One would expect it would pick a random item from the Family (the collection of my sprites),

    but it always shows only the last one of the Family.

    Than I tried 'Pick by evaluating' so I did choose Family again and filled in my Local Variable: Name.

    But Nada.

    So this is not the way...

    I guess I am looking in the wrong direction...

    Could anybody help me or just point me in the right direction?

    Thanks again Nimos and everybody else who wants to explain this to me.

    Philip

  • If your sprites are all basically the same, why not use animations instead of different objects and just set a random (or specific) animation after creating..

    I do believe there is a third party plugin that does exactly what you are asking, I believe it's called nickname..

  • Thanks a lot for the tip LittleStain, I downloaded it and will play with it. Great advise, now I feel I am moving to the right direction.

  • Philip99 You could also use checks for a random UID (unique ID) or IID (instance ID; if you're spawning objects and run the check inside the condition they're generated, use this). If you're spawning multiples of one sprite, you can try:

    System -> On start of layout

    • (Sub-event) family_enemies -> Pick instance with UID (random(1,maxNumOfSpawnsHere))

    ---- Add events here for your power-up to apply to this picked instance.

    If running the power-up check inside the main condition where the sprites are spawned, use IID and place the check for IID as a sub-event somewhere after spawning.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)