How do I

Get help using Construct 2

Post » Wed Feb 01, 2017 7:14 pm

hi there ive got a problem which is annoying lol.

im new to arrays but i thought id start using them in my project as its important to learn arrays. so i started off with something simple which follows.

on object clicked - push "Barracks" on x axis (((array)))
set value at (array.curx , 1) to globalvarible * 120 (((360)))

so this adds an array of Barracks,360
which works out perfect, so the next bit of code i want to happen is every 1 second subtract 1 from the 360 until it reaches 0 so i used code

for each x element
every 1 second - set value at (array.curx , 1) to array.curvalue - 1
timer = true

the reason ive done the code like this is i plan to add several more items to the array each with its own timer in Y, so i constantly want it to subract 1 from each Y until it hits 0 but the code just sets the array to (barracks,barracks) so im not sure what im doing wrong. i hope this makes sense.

im sorry havent provided a .capx file as its a secret project also a screenshot would be hard as the codes are all under seperate categorys on different pages which would mean alot of copy and pasting
B
19
S
6
Posts: 143
Reputation: 1,835

Post » Wed Feb 01, 2017 10:35 pm

can anyone enlighten me please. i think the problem is with this code set value at (array.curx , 1) to array.curvalue - 1
B
19
S
6
Posts: 143
Reputation: 1,835

Post » Wed Feb 01, 2017 10:35 pm

It is viewed unfavorably for you to bump your own topic within 24 hours.

If your project is secret/complicated, at least you could make a new project isolating the issue you are having trouble with. You would be able to get help quicker and more accurate assistance.

But from what I can see, the problem is:
every 1 second - set value at (array.curx , 1) to array.curvalue - 1

This should be array.at(array.curx, 1). See if that works?
Mistakes were made.
B
52
S
26
G
109
Posts: 1,606
Reputation: 61,633

Post » Wed Feb 01, 2017 10:39 pm

for each x element
every 1 second - set value at (array.curx , 1) to array.curvalue - 1
timer = true


Value at(a,b) implicates that this is a 2D array. With index a on the X axis. And index b on the Y Axis.
For each element x ... runs trough all indexes on the X-axis. Meaning the array.curvalue contains a value stored on the X Axis (only).
So, yes, you store on each each index 1 on the Y axis ... for each index on the X axis .. the value that is stored on that X axis.

Rather.

I like to recommend a global variable to remember what the Y axis is meant to be.
Say Global variable 'Counter_Y' (number) = 1

Every 1 second
System ... For "index_X" .. from 0 .. to array.width - 1
______Array ... set value at (loopindex("index_X" , Counter_Y) to Array.At(loopindex("index_X" , Counter_Y) - 1
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Feb 01, 2017 11:08 pm

hey thanks alot for the replies. did i mention im new to arrays? :D i dont really understand the code you've put 99instances. and oosyrag how to i change to array.at? i only know how to do that as part of array actions. then im not sure where im actually ment to put it :D but to explain the array better im trying to have the array have research names on x axis and the timer until its research on the x axis below it so y1. then the plan is when it hits 0 ill use if array contains 0 put cur x into another array with all research items. also im trying to do it in an odd way as you might be researching loads of different things at the same time with different times.

p.s i dont usually bump but this problem has been giving me a headache all day
B
19
S
6
Posts: 143
Reputation: 1,835

Post » Wed Feb 01, 2017 11:35 pm

oosyrag i worked out what you ment and it worked. i thank you kind sir :D ive been pulling my hair out over this :P.

ok so i was wrong i got the next one working but now it doesnt count down both of the arrays just the first one thats added any ideas?
B
19
S
6
Posts: 143
Reputation: 1,835


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, Phacanu, RODInteractive, Txchaser and 25 guests