Fill Array with Sprites

Get help using Construct 2

Post » Thu Jun 23, 2016 6:12 pm

Edit:
Dude, i have no idea why i wrote all this, i think i reacted on an old post. Deeply sorry, to proud to just all delete it.
Tired from work i guess.

















I dont recall using visible/invisible in any of the examples i gave you. I do recall using 1 sprite with all items as a frame in an animation, and a empty frame (frame zero) to represent the 'not found yet' condition, for the book. That simplified a lot of things, including the situation where you would decided to use an array.

I have no idea how you do this now, iffen you talk about setting an object visible/invisible.

The sprite.IID is an index. An index means a position in a list. All lists in construct are zero based. Wich list ? In case of the IID it is the position of a sprite in the picklist. If you made footsteps in the layout, and you made them in order, then, when you pick them all, the IDD returns that order. So IID zero is the first one you made in the layout, IDD 1 is the second one you made ... and so on. Hence, you have to create them in the right order.

Again stressing this 'picklist'. Would you pick the steps that are 'visible', then you make a total other picklist. With other (probaly less) objects in that list. So, those picked objects have another IDD.

The same objects are in another position (in the picklist) when you 'pick all' compared to 'pick visible'. See it this way. There are 10 appels on the table. When you take them all, you 10 apples picked. If you make a list of those 10 apples, then this list contains 10 apples and each apple is in a postion in the list = IDD. Now if you take only the last 5 apples. You have 5 apples picked, and the apple that was in the list on position 4 when all apples picked is now on position zero.

In short: IDD depends on wich objects are picked.

For your collectables, if they are in the new layout made in a differend order, then they have differend IID's in both layouts, when you pick them all. That is probaly your first problem.

The easy way to go with this is like .... Make a start layout with all the global objects in, on dedicated layers. Global objects !. And just go to the first game layout. The global objects will go with you. For the collectables, this the solution. All collectables must be in that 'start layout'.

But that means also that you have place each object in an event. Better is to drop the IID construction. And give each instance a instance variable with a unique number. And use that to identify it.

The book and its sprites must be global. If you use no array, the book does not need to updated when changing layout. Its just fine.

When using a global array + global objects, the book does not need to be updated when changing layout. (not to my knowledge)

About the array. Getting things out of it.

First you must understand that an array is a list. Lists go with indexes. A value sits on a certain index. The index is in the form of city,street,housenumber (x,y,z). The value can be number (3 dogs living there). Or a string ("Lukaku" living there)

Forget the z. You wil kinda never need to use it. So from now on i speak about x,y.

Now, the X axis is any position in the array (number,zero)
(7,0) lays on the X-axis. So does (12,0) and (9999,0).
As you see, the X-as is using the zero index on the Y-axis. Or, an array containing only values on the X-as (1Dimensional) must have a size of (amount of x,1,1).
This is what you have, and there is no room for additional values on the Y-position. I do not talk about the Y-axis, because using the term Y-axis has only sense in a 3D array, when (ofcourse) the Y position is using the zero position of the Z-position.
So we talk about the X-axis and about Y-postions. X-axis any position in the array where the Y-positon is zero (x,0).

X-axis and Y position.

So if you want to store values on Y-positions, the size of the array must be (amount of x, amount of y + 1). Else there is no (5,1) or (5,7) or (5,9999) available. (5,0) = de X-axis.

Why is this importand ? Because we usaly want to loop on the X-axis. We usaly want to push and pull on the X-axis.

Okay, back to index and value. To start with the expressions. There are expressions for values. And there are expressions for the index.

For the in index ....
CurX
CurY
CurZ
The current zero-based index for each dimension in a For each element loop.

For the value ....
At(X)
At(X, Y)
At(X, Y, Z)
Retrieve a value at a position in the array. Indices are zero-based. Reading values outside the array returns the number 0. If the Y or Z indices are not provided then 0 is used.

CurX has only a meaning when using a array > 'For each element' loop condition. CurY and curZ i only use when dealing wit a 3D array.

So, when you use the loop 'For each element X', this loop is running over each POSITION on the x-axis.
The expression CurX returns the position where the loop is at that moment.
So the value is at Array.At(CurX,Y-position)

But you can use any loop. If you have instances with a instance variable containing a number (dont forget first number should be zero, not 1) then you can ....
For Each Ordered (by that instance variable)
The value is now at Array.At(sprite.instancevariable,Y-positon)

You can use a regular For loop.
From "i" 0 to sprite.count - 1
value = Array.At(loopindex("i"),Y-positon)
pick nth instance .. n = (loopindex("i"))
action ... set sprite.somevariable to value

But you dont need a loop to retreive one item from the array.
The value is just at Array.At(X-position,Y-postion)

Storing in the array is just the same. Same conditions, only now we need ACTIONS.

You can use a regular For loop.
From "i" 0 to sprite.count - 1
Set at XY ... x =loopindex("i") ... y =Y-positon ... value = the value you want to store

Or a For Each Ordered (by that instance variable)
Set at XY ... x =sprite.instancevariable ... y =Y-positon ... value = value you want to store

Or just, with no loop
Set at XY ... x = X-position ... y =Y-positon ... value = value you want to store

Hope this clears some things out so you can manage what you want to. I have no idea what you are actual dooing. But i see that the size of your array is to small. And i see that you try to set the 'numbers' or the 'IDD' on the Y-Axis, and that will make it to complicated, also for me.

If you want a numberd list, trow them in the X-axis (x,zero).
Any other value goes on the Y-position. (x,y-position)
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Jun 24, 2016 5:19 pm

@99instances2go wooooooooooohow that was unexpected :) amazing description and you did this, because youre crazy of course :D . Thank you very much for your time, you invest into this. I think you need holidays :D

There is one last thing remaining iam onto code for this game. The last step. After your supprot iam much better in understanding the tools and events in construct2 thanks for that!

Basically level_1 is done. This is the level, where you have to find the footsteps and fill your inventary book with some informations (or random events) you can collect durring the playtrough.

Currently iam on level_2. In this level you have to find the right path trough a cave. This cave has 3 "doors" you can choose. Basically level_2 is splittet into 3 Rounds. In round 1 you got one symbol on each "door". in round 2 you got 2 symbols on each door and of course in round 3 you got 3 symbols on each door. In each round, there is only one symbol, which is the right one. Therefore you can check your inventary book to compare the complete symbols with eachother.

Iam writing down the tasks, maybe you got an idea how to handle this straigth (like you did before on the other tasks, i had problems with ;) (Thanks again for your awesome support by the way) )


Setup:
Ive created spawning areas (sprites) whit its dimensions are dynamicaly changable. Inside this areas the symbols should spawn, so when i change the size or the position of the sprites, the symbols will be spawn on the changed values too. This works perfectly so far - but not for the whole game logic i would need. Currently i can spawn objects i have "fixcoded" from a "non array based" event.


Now the difficould part:

If you want to start level 2, round 1 should set up three symbols (one on each door), which will be loaded from an array (i think now i have to use arrays (later more)). This symbols have to be spawned on each spawning sprite (i told above) on a random position (this works but like i said not with arrays but with fix coded sprites).

But now i have to choose the sprites more "controlled" because in level 1 there is one "correct" footstep you have to follow, and on which you can find the specific symbols too. so basically there are four different footsteps, with three specific symbols you can find, and which are filled into the inventory book. One of this paths is the right one but you have to find out which one.

in level 2 you have to find the right way, but if you didnt found the symbols, youre maybe lost, because you cant know which symbols are the right one.

So in round 1 there will be one right symbol on a door and two false symbols on the other ones. in round 2 there are two symbols on each door, but one of them is the right one. in round 3 its basically the same thing except there are 3 symbols (and one of them is the right one - so you have to check your inventory book and compare the symbols)

now the main thing is - you can leave level 2 to find more symbols if you didnt found them before to make you inventory book complete, but if you return in level 2 the symbols should be on the same place.

Therefore:

Ive created 4 arrays.

Array 1: My basic symbol pool: All symbols i have to use from my main sprite with the differend animation sprites (your idea :D ).
Array 2 - 4: Basically the array with the specific informations about which symbol was randomly choosed, and on which position it was placed (the position should be saved and loaded, if i leve level 2 and return into because it is a different layer and a part i forgot to tell is that you cann fall back into round 1 if you fail in round 2 or 3 (because its a cave and you choosed the wrong path you will walk into nothing and start again)). But the symbols in round 1,2 and 3 should be on the same place. Thats the reason i would have to store this informations about it.

I know its not easy to understand or may my description is not so good :). But iam currently working on this task and i would be very happy if you could give me some adivices how i could solve this. Maybe your workfolw will be much more better than mine. (Iam sure it will)


Currently iam on the step:

Fill the Arrays for each round with baically one right sprite and two other ones.

99Instances2Go - if this game is finished you will be one of the first gamer if you want to ;)

Thank you very much!
Last edited by Congrats2u on Fri Jun 24, 2016 5:25 pm, edited 1 time in total.
B
9
S
2
Posts: 152
Reputation: 1,051

Post » Fri Jun 24, 2016 5:22 pm

Ps: i use your informations you gave me in your last post for this task :) so its very usefull for my current task!

ive got 12 symbols, i saved in this "array_pool" and 3 of them are the "right" symbols (symbol 1- 3). For each round i have to take out one of the "right" smybols (to avoid they will be used two times). The other symbols can appear two times on differend rounds - that wouldnt be dramatic.

in the next round (round 2) there are only two right symbols (for example symbol 1 was used in level 1 now the system should choose between array position 1 and 2 for symbol 2 and 3). The rest symbols could be the other array slots (4 - 11 or symbol 4 to 12). In round 3 the last "right" symbol should be choosed - the rest can be filled again with the rest symbols (again array position 4 - 11 or symbol 4 to 12).

The advanced task is to save each round like i descriped in the post before, if the player failes in one level and has to do round 1 - 3 again. puuuuuuuuuuuuuuuuuuuuuh crazy stuff....

Thats difficould in my oppinion.
B
9
S
2
Posts: 152
Reputation: 1,051

Post » Fri Jun 24, 2016 7:14 pm

The symbols need numbers (instance variables) that correspondent with their framenummers. This way you have the right face by the right index in the array. On the y-positions, you store things like if they are found (1 or zero), wich level they are .... and so on.

But also a number that correspondents with the doors. The doors (their spawners) need numbers (instance variables). All of them and unique. So, 1,2,3 for the first level. 4,5,6 for the next level.

Now you have (on a y-postion, lets say position 1) on array(symbolnumber,1) the info that its found or not. A 1 means found. A zero means not found. If it is 1 it goes to show in the book.

You can do the same with the doors. Say on array(symbolnumber,1) you set door number. And say, if it is a zero, the door is not chosen yet. Else it is chosen. Not chosen yet, choose. And display.

https://www.dropbox.com/s/qabnmfbu2p2o1 ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat Jun 25, 2016 4:10 pm

B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Jul 01, 2016 6:17 pm

@99Instances2Go Hey 99 - sorry i was buisy with another project iam working on...

Now iam working on this task again. And its frustrating....because i was inspired by your choose(x,y,z) function. But its weird. Ive included a image file (again i couldnt include it because of my low reputation points - but i did it like i did before ;) ).

I got 3 values who needs to be differend to spawn my objects on three differend doors....but on the while condition for door 3 - the event gets called - even if the value is the same one like on door 2 and 1 - and thats absolutly false... and shouldnt happen.

Ive got the randomizing function - but why the hell is the event called when only one of the two condition is true? This shouldnt happen in my opinion.

graphic link:
postimg.org/image/6gbwl3ykn/

If i start the project sometimes its correct and sometimes its wrong
this is an excample of how it should look:
postimg.org/image/8qygh44i9/

and this is an excample how it looks sometimes...
postimg.org/image/xg7bqqo7b/

(the problem part is marked with this red symbol :) )


It would be so nice if you could tell me what iam doing wrong - thank you very much! :)

Best regards!
B
9
S
2
Posts: 152
Reputation: 1,051

Post » Fri Jul 01, 2016 10:54 pm

Plz look again @ the example. Yours is way off. I dont recall using an or.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Jul 07, 2016 2:51 pm

@99Instances2Go

Okay it works fine now :) thanks for this!

New day - new question: Is it basically possible to animate sprites? If i found a Footstep, i want to scale it up from 0.1 to 1.2 and then back to 1.0 (like a "plopp up" animation). Is there a possibilaty to do this in construct2 without using tweenlite or something?

I have no experience with tween lite - and i dont know if it will decrease the performance of the game, if i would use it.

Thank you very much and best regards!
B
9
S
2
Posts: 152
Reputation: 1,051

Previous

Return to How do I....?

Who is online

Users browsing this forum: MrSkailo and 23 guests