This forum is currently in read-only mode.
0 favourites
From the Asset Store
40 ambient sound loops. A wide selection of looping ambient sounds for different locations.
  • Hi all,new to Construct,and even newer to the forum,been bashing my head on a wall for three days,trying to work out,how to use an array,or any method really,to give me one of ten random objects,without duplicating the "pick".array seems most suited,and feel it is something "I need to know"

    Now,I kinda get how arrays work,after reading up on them,and understand the check if "picked",repeat till ten process,but can't really grasp how,you manipulate that info into a usable,effect.

    read loads of examples and loaded caps,but most are using system commands,that seem beyond me at the moment,as I want to understand what I am doing,rather than,copy-paste,somebodys example.purchased the Construct game development book by Daven Bigelow,few weeks ago,and arrays are barely mentioned,bit of a hurdle for my project as I can't focus until I get this beat.

    I feel the array command is lacking flexability,somehow,as I can only seem to see the value at random x,or change the value,to something I dont want to change it to!,sure I'm missing something obvious to most.

    so I am looking for a simple basic explanation,of how the array is used with the loop to give me a once only pick from ten.

    Any help would be apprieciated,and apologies if this is covered elsewher,if so I missed it.thanks in advance.

    PS using construct classic r2

  • Hi! Thanks for getting my book <img src="smileys/smiley1.gif" border="0" align="middle" /> Would you be able to upload a cap file of what you're trying to do?

    From the sounds of it, you're looking to pick a random object out of 10 with no other conditions for picking them such as: distance away from a central point or pick 10 from many more, and then pick one from this ten. Is that correct?

  • Jayjay,thanks for response,book has been a good hands on reference with the patchy nature of construct's online documentation.

    I want to understand how the array is used specifically with the loop to eveluate if it has been chosen.

    not sure how to post a cap example,but in game my player,picks up one of ten objects,each is the same sprite,but I want to randomly give the player one of a "pool" of ten bonuses,once given I want it removed from the "pool",giving the impression that each sprite is an individual.

    I have set up an array with ten names,I can get the array to give me the names in random,using a text box,random(10)+1 current.x but cant "pull" that into anything useful,I can only find a command to change the value at a random....which leaves me at square one <scratches head>....

    I have tried various ways of doing so,think array with a loop is way to!,regards.

  • sounds like you need a global value to store the random number, insted of getting a random one each time?

    and with dealing in array you often have to use str() and int(). not sure if thats what you got going on, but that often happens to me.

  • Ah I see, and you can use DropBox to easily upload files =)

    Is this what you're going for?

  • Jayjay,your a star!....just had a quick look over it and it looks like just what I need,later I will try and adapt the procedures into my project,thanks for your help I really appreciate it..:)

  • Awesome, glad to help Pixel perfick <img src="smileys/smiley4.gif" border="0" align="middle" />

  • update....Jayjay I have intergrated your steps into my project applying the guide you very kindly passed on.

    And managed to get it half working,as in it will display randomly some/most of the time,but sometimes repeats,adds two to the count,or in my game will not let me collect the tenth sprite...

    however after 3 hours of head-scatching and double checking...I decided to give your tutorial a debug to see what the "values" told me....and I'm afraid your example does the same....bit releaved to be honest...he he...thought I had done something wrong....

    any chance you can look over your example,again please,many thanks...

  • Ah oops, sorry about that! I'll take a look at it tonight

  • Hmm, that's strange, I can't replicate the issue you're having. I've modified the cap file to make used entries blank though for easier debugging:

    A simpler work-around is to create 10 sprites of size 2x2 (power of two textures won't cause any real issue on the graphics card), and position them way outside the layout.

    Have their powerup ability as a private variable and then when the player touches the object sprite, you pick one of the the powerup selector sprites at random, grab its powerup variable and destroy it. This way we rely on Construct Classic's internal arrays <img src="smileys/smiley1.gif" border="0" align="middle">

    I'll make a cap file of that method if you'd like

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Mmmm,that's odd...I will try the cap again,and let you know how I do.

    Thanks for taking time out to check and amend the cap,the hidden sprite idea,maybe food for thought,too.and if it's no problem be worth looking at as an option.

    thanks again.

  • ....Ok,just to add to my confusion,trying your original cap again,it seems to be working perfectly...all I can think of is that I moved/deleted a condition or event inadvertantly...ooops...sorry!

    I will go over my project again later...and let you know how I get on...

  • Heh glad to hear it's working at least! Good luck with your project <img src="smileys/smiley4.gif" border="0" align="middle" />

  • Ok,Jayjay,I have muddled together a mixture of your way and mine as my project involves the sprites being destructable,which I think was causing issues with your method in my game...still not 100% on loops,how do I use a loop to check a variable...once the first condition is met...the loop checks through possibles and if one (or more)is a "hit"> do something...if not carry on regardless...I can only seem to get the first checked or a constant flow of does a sub event differ from a condition inside the main trigger?

    can I just add thanks,for your help...and loops do my head

  • A bit off topic but how do I open these .cap files? I'm trying to use Construct 2 to open them. And how do I create them from my own project? Thanks

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