Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with a 'for' loop
Kullin1337 Offline
Junior Member

Posts: 8
Threads: 2
Joined: Apr 2015
Reputation: 0
#1
Need help with a 'for' loop

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);
}
}
05-27-2015, 09:46 AM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#2
RE: Need help with a 'for' loop

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: (Select All)
FadeLightTo("torch_floor_" 90001, -19);
FadeLightTo("torch_floor_" 80001, -18);
FadeLightTo("torch_floor_" 70001, -17);
FadeLightTo("torch_floor_" 60001, -16);
FadeLightTo("torch_floor_" 50001, -15);
FadeLightTo("torch_floor_" 40001, -14);
FadeLightTo("torch_floor_" 30001, -13);
FadeLightTo("torch_floor_" 20001, -12);
FadeLightTo("torch_floor_" 10001, -11);
FadeLightTo("torch_floor_" 00001, -10); 

Does it look okay to you?

05-27-2015, 10:04 AM
Find
Kullin1337 Offline
Junior Member

Posts: 8
Threads: 2
Joined: Apr 2015
Reputation: 0
#3
RE: Need help with a 'for' loop

(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: (Select All)
FadeLightTo("torch_floor_" 90001, -19);
FadeLightTo("torch_floor_" 80001, -18);
FadeLightTo("torch_floor_" 70001, -17);
FadeLightTo("torch_floor_" 60001, -16);
FadeLightTo("torch_floor_" 50001, -15);
FadeLightTo("torch_floor_" 40001, -14);
FadeLightTo("torch_floor_" 30001, -13);
FadeLightTo("torch_floor_" 20001, -12);
FadeLightTo("torch_floor_" 10001, -11);
FadeLightTo("torch_floor_" 00001, -10); 

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.
05-31-2015, 03:58 PM
Find
Daemian Offline
Posting Freak

Posts: 1,129
Threads: 42
Joined: Dec 2012
Reputation: 49
#4
RE: Need help with a 'for' loop

Try one of those lines outside the loop.

05-31-2015, 11:56 PM
Find
Kullin1337 Offline
Junior Member

Posts: 8
Threads: 2
Joined: Apr 2015
Reputation: 0
#5
RE: Need help with a 'for' loop

(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!
(This post was last modified: 06-01-2015, 12:22 PM by Kullin1337.)
06-01-2015, 11:20 AM
Find




Users browsing this thread: 3 Guest(s)