ARRAYS & LOOPS FOR DUMMIES...

For questions about using Classic.

Post » Sun Nov 18, 2012 8:19 pm

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

As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260

Post » Mon Nov 19, 2012 3:24 am

Hi! Thanks for getting my book 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?Jayjay2012-11-19 03:24:48
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Mon Nov 19, 2012 8:44 am

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 go.....help!,regards.

As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260

Post » Tue Nov 20, 2012 2:49 pm


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.
B
6
S
2
G
5
Posts: 249
Reputation: 2,323

Post » Tue Nov 20, 2012 2:56 pm

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

Is this what you're going for? https://dl.dropbox.com/u/4714446/ArrayPowerups.cap
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Tue Nov 20, 2012 4:20 pm

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..:)
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260

Post » Tue Nov 20, 2012 11:54 pm

Awesome, glad to help Pixel perfick
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Thu Nov 22, 2012 12:43 am

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...
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260

Post » Thu Nov 22, 2012 6:51 pm

Ah oops, sorry about that! I'll take a look at it tonight
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Fri Nov 23, 2012 8:38 am

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: https://dl.dropbox.com/u/4714446/ArrayPowerups.cap

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

I'll make a cap file of that method if you'd like
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests