LC to C-script

Posted By: CodeMaster

LC to C-script - 06/25/12 17:35

for(i = 0; i < j; i ++)

How write this in c-script?
Posted By: 3run

Re: LC to C-script - 06/25/12 17:39

"for" loop works only with lite-c. I guess you can some how work around it, but I'm not sure. The main idea is, that loop runs till "i" is smaller than "j" in the example you've posted above. Play with loops, may be you could find a way to handle it.
Posted By: Rei_Ayanami

Re: LC to C-script - 06/25/12 17:46

i = 0;
while(i < j)
{
//code here
i++
}
Posted By: 3run

Re: LC to C-script - 06/25/12 17:54

Rei_Ayanami@ you screwed everything up grin I wanted him to come to that point himself!
Posted By: CodeMaster

Re: LC to C-script - 06/25/12 18:04

first thanks for help guys!

i think this will not work beacuse i must put this in while loop and then i=0 will be whole time zero, and i++ also will report error in c-script.

There is complete function where i need this
Code:
action act_emitter()
{
	while(1)
	{
		for(k = 0; k < 3; k++)
		{
			p_lightning1_size = 4+random(4);
			i = vec_dist(my.x,p_effect_target);
			j = floor(i/32)-1;
			vec_set(temp,my.x);
			vec_set(temp3,my.x);
			for(i = 0; i < j; i ++)
			{
				vec_diff(temp2,p_effect_target,temp);
				vec_normalize(temp2,32);
				vec_add(temp3,temp2);
				temp3.z += (1-random(2))*(8+k*3);
				vec_diff(temp2,temp3,temp);
				effect(p_lightning1,1,temp,temp2);
				effect(p_lightning2,1,temp,temp2);
				vec_set(temp,temp3);
			}
			vec_diff(temp2,p_effect_target,temp);
			effect(p_lightning1,1,temp,temp2);
			effect(p_lightning2,1,temp,temp2);
		}
		
		my.tilt += 2*time_step;
		my.tilt %= 360;
		vec_set(temp,vector(700,0,0));
		vec_rotate(temp,my.pan);
		vec_add(temp,my.x);

		c_trace(my.x,temp,IGNORE_MODELS);
		if(trace_hit)
		{
			effect(p_laser_hit,3,target,normal);
			vec_set(temp,target);
		}
		vec_diff(temp2,temp,my.x);
		j = vec_length(temp2)/16;
		for(i = 0; i < j; i++)
		{
			vec_lerp(temp3,my.x,temp,i/j);
			effect(p_laser,1,temp3,temp2);
			effect(p_laser2,1,temp3,temp2);
		}
		time_factor = 1-key_ctrl*0.75;
		wait(1);
	}
}


Posted By: 3run

Re: LC to C-script - 06/25/12 18:14

I won't fix that (but it's really easy :> ). Use simple work around for setting variable to zero. Something like this:
Code:
function blahblah(){
	var run_at_once = 1;
	while(1){
		if(run_at_once == 1){
			....
			
			// all stuff you'll insert in here, will run only once
			// will you'll set "run_at_once" again to "1"
			
			...
			run_at_once = 0;
		}
		wait(1);
	}
}

For "i++" you shouldn't use exactly that, Rei just showed you the place of "i++" from the "for" loop.
Instead of that, you need to create a var, insert set it to the initial value, make a comparison (as in "for").
And then increase it by 1 each tick, that will do the job, this is really first steps which you need to handle yourself.

Edit: I've just made it myself :>

Code:
action act_emitter(){
	// variables:
	var run_once[3];
	var comp_var[3];
	var end_var[3];
	// set start for "once" variable:
	vec_fill(vector(run_once[0], run_once[1], run_once[2]), 0);
	// main loop:
	while(1){
		// init first end var:
		end_var[0] = 3; // as in the script
		// init first start var:
		if(run_once[0] == 0){
			comp_var[0] = 0; // init!
			run_once[0] = 1;
		}
		// first fake "for" loop:
		while(comp_var[0] < end_var[0]){
			// init second end var:
			end_var[1] = 3;
			// init second start var:
			if(run_once[1] == 0){
				comp_var[1] = 0; // init!
				run_once[1] = 1;
			}
			// second fake "for" loop:
			while(comp_var[1] < end_var[1]){
				// increase second loop variable:
				comp_var[1] += 1;
				wait(1);
			}
			// increase first loop variable:
			comp_var[0] += 1;
			wait(1);
		}
		// init second end var:
		end_var[2] = 3;
		// init second start var:
		if(run_once[2] == 0){
			comp_var[2] = 0; // init!
			run_once[2] = 1;
		}
		// third fake "for" loop:		
		while(comp_var[2] < end_var[2]){
			// increase third loop variable:
			comp_var[2] += 1;
			wait(1);			
		}
		wait(1);
	}
}


Posted By: CodeMaster

Re: LC to C-script - 06/28/12 12:24

thank you 3run i will try your code
© 2024 lite-C Forums