Frictional Games Forum (read-only)
Need help with a 'for' loop - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: Need help with a 'for' loop (/thread-30053.html)



Need help with a 'for' loop - Kullin1337 - 05-27-2015

Hi, so I have a 'for' loop that won't work. It doesn't give me errors, but when I walk into the area nothing happens.

Here's the code:

{
AddEntityCollideCallback("Player", "Lights_Fade_area", "Lights_Fade", true, 0);
}

void Lights_Fade(string &in asParent, string &in asChild, int alState)
{
for(int i = 9; i >= 0; i--)
{
FadeLightTo("torch_floor_" + i, 0, 0, 0, 1, -1, 9 - i);
}
}


RE: Need help with a 'for' loop - Mudbill - 05-27-2015

First check to make sure the collision event is actually ran.

Now, why does the for-loop count down from 9 to 0 instead of up from 0 to 9? Also, why is the last argument 9-i? Is this a mix of different light objects that are supposed to light up after each other, as in #9 takes 0 sec, #8 takes 1, #0 takes 9 etc?

Here's the code this for-loop generates:

PHP Code:
FadeLightTo("torch_floor_" + 9, 0, 0, 0, 1, -1, 9 - 9);
FadeLightTo("torch_floor_" + 8, 0, 0, 0, 1, -1, 9 - 8);
FadeLightTo("torch_floor_" + 7, 0, 0, 0, 1, -1, 9 - 7);
FadeLightTo("torch_floor_" + 6, 0, 0, 0, 1, -1, 9 - 6);
FadeLightTo("torch_floor_" + 5, 0, 0, 0, 1, -1, 9 - 5);
FadeLightTo("torch_floor_" + 4, 0, 0, 0, 1, -1, 9 - 4);
FadeLightTo("torch_floor_" + 3, 0, 0, 0, 1, -1, 9 - 3);
FadeLightTo("torch_floor_" + 2, 0, 0, 0, 1, -1, 9 - 2);
FadeLightTo("torch_floor_" + 1, 0, 0, 0, 1, -1, 9 - 1);
FadeLightTo("torch_floor_" + 0, 0, 0, 0, 1, -1, 9 - 0); 

Does it look okay to you?


RE: Need help with a 'for' loop - Kullin1337 - 05-31-2015

(05-27-2015, 10:04 AM)Mudbill Wrote: First check to make sure the collision event is actually ran.

Now, why does the for-loop count down from 9 to 0 instead of up from 0 to 9? Also, why is the last argument 9-i? Is this a mix of different light objects that are supposed to light up after each other, as in #9 takes 0 sec, #8 takes 1, #0 takes 9 etc?

Here's the code this for-loop generates:

PHP Code:
FadeLightTo("torch_floor_" + 9, 0, 0, 0, 1, -1, 9 - 9);
FadeLightTo("torch_floor_" + 8, 0, 0, 0, 1, -1, 9 - 8);
FadeLightTo("torch_floor_" + 7, 0, 0, 0, 1, -1, 9 - 7);
FadeLightTo("torch_floor_" + 6, 0, 0, 0, 1, -1, 9 - 6);
FadeLightTo("torch_floor_" + 5, 0, 0, 0, 1, -1, 9 - 5);
FadeLightTo("torch_floor_" + 4, 0, 0, 0, 1, -1, 9 - 4);
FadeLightTo("torch_floor_" + 3, 0, 0, 0, 1, -1, 9 - 3);
FadeLightTo("torch_floor_" + 2, 0, 0, 0, 1, -1, 9 - 2);
FadeLightTo("torch_floor_" + 1, 0, 0, 0, 1, -1, 9 - 1);
FadeLightTo("torch_floor_" + 0, 0, 0, 0, 1, -1, 9 - 0); 

Does it look okay to you?
I honestly don't know why I named them that why, and since I placed them before writing the code I decided that it was better to count down.
The collision event runs, made sure to check that with a message.
And yes, the generated code looks right.


RE: Need help with a 'for' loop - Daemian - 05-31-2015

Try one of those lines outside the loop.


RE: Need help with a 'for' loop - Kullin1337 - 06-01-2015

(05-31-2015, 11:56 PM)Daemian Wrote: Try one of those lines outside the loop.
That doesn't work either.

Edit: I'm a retard. I used the wrong function. The right one is:

SetLampLit(string& asName, bool abLit, bool abEffects);

However, now I get an error saying: ERR: Unexpected token 'for'.
Do you know how to fix that?

Edit2: It works, thank you for helping me out!