E
Edwin
Guest
Code:
// Create Event
array[0] = 0;
array[1] = 0;
array[2] = 0;
// Step Event
if (keyboard_check_pressed(vk_right)) {
array[random(array_length_1d(array))] += 1;
}
Please help!
// Create Event
array[0] = 0;
array[1] = 0;
array[2] = 0;
// Step Event
if (keyboard_check_pressed(vk_right)) {
array[random(array_length_1d(array))] += 1;
}
for (var i=0;i<array_length_1d(array);i++) {
if (array[i] > 0) {
array[i]++;
}
}
var inc = false;
var size = array_length_1d(array);
for (var i=0;i<size;i++) {
if (array[i] > 0) {
inc = true;
}
}
if (inc) {
for (var i=0;i<size;i++) {
array[i]++;
}
}
if (variable == true) {
//Do code
variable = false;
}
So basically I want to check if any of the array's value is greater that 0, then keep it adding 1 to the array.Code:// Create Event array[0] = 0; array[1] = 0; array[2] = 0; // Step Event if (keyboard_check_pressed(vk_right)) { array[random(array_length_1d(array))] += 1; }
Please help!
var len = array_length_1d(array);
for (var i = 0; i< len; i++) {
if (array[i] > 0) {
array[i] ++;
}
}
Do you want the 1 to get added only to the entry that is greater than one? If so:
If you want them all to get 1 added if any is above 0 then:Code:for (var i=0;i<array_length_1d(array);i++) { if (array[i] > 0) { array[i]++; } }
EDIT: You can't just put these in the Step Event btw, otherwise the array values will increment wildly. You'll have to put them behind some sort of check, whether it be an alarm, a boolean check:Code:var inc = false; var size = array_length_1d(array); for (var i=0;i<size;i++) { if (array[i] > 0) { inc = true; } } if (inc) { for (var i=0;i<size;i++) { array[i]++; } }
Etc, just something to stop it from happening every step.Code:if (variable == true) { //Do code variable = false; }
Thanks alot eveyone! I made it and I have a second question here. I'll be glad to you guys help meI cant test this code write now but I beleive it should work. Basically you use a for loop to cycle through all the arrays, and if an array value is greater than 0 increase the array value by 1.Code:var len = array_length_1d(array); for (var i = 0; i< len; i++) { if (array[i] > 0) { array[i] ++; } }