"invalid loop block structure"?

Post » Tue Dec 06, 2011 7:24 am

Why am I getting a CS error for an "invalid loop block structure"?


scn aadpArrayTestfloat fquestdelaytimearray_var ListOfActorsarray_var ActorRefArrayarray_var TargetRefArrayref targetref Actorbegin GameModeif ( player.isincombat == 0 )set fquestdelaytime to 5returnelseset fquestdelaytime to .3let ListOfActors := ar_Construct Array;---- Create the listsset Actor to GetFirstRef 69   while ( Actor )      if IsFormValid Actor == 1         if Actor.getdisabled == 0 && Actor.getdead == 0           ar_append ListOfactors Actor;--- add actor to the list of actors         endif      endif     set Actor to getNextRef   loopForEach ActorRefArray <- ListOfActors;--- set array called ActorRefArray to the actors in the array called ListOfActorsLet Actor := ActorRefArray["Value"];--- set ref called actor to the next actor in the array called ActorRefArray   while ( actor )      ForEach TargetRefArray <- ListOfActors      Let Target := TargetRefArray["Value"]         while ( target )             if target.GetLOS actor == 1                messagebox"worked"            endif         loop   loopendifend

User avatar
sam westover
 
Posts: 3420
Joined: Sun Jun 10, 2007 2:00 pm

Post » Tue Dec 06, 2011 7:56 am

By being careful to indent correctly, the errors are quite easy to spot:

if ( player.isincombat == 0 )	set fquestdelaytime to 5	returnelse	set fquestdelaytime to .3	let ListOfActors := ar_Construct Array;---- Create the lists	set Actor to GetFirstRef 69	while ( Actor )		if IsFormValid Actor == 1			if Actor.getdisabled == 0 && Actor.getdead == 0				ar_append ListOfactors Actor;--- add actor to the list of actors			endif		endif		set Actor to getNextRef	loop	ForEach ActorRefArray <- ListOfActors;--- set array called ActorRefArray to the actors in the array called ListOfActors		Let Actor := ActorRefArray["Value"];--- set ref called actor to the next actor in the array called ActorRefArray		while ( actor )			ForEach TargetRefArray <- ListOfActors				Let Target := TargetRefArray["Value"]				while ( target )					if target.GetLOS actor == 1						messagebox"worked"					endif									loop	loopendif

User avatar
elliot mudd
 
Posts: 3426
Joined: Wed May 09, 2007 8:56 am

Post » Tue Dec 06, 2011 5:59 pm

oh for god sake... wow ...thanks TheNiceOne!

But It was not the indenting that was my issue it was that I did into know FOREACH was a type of loop.

mmmm..... I need to re-read the description of FOREACH in the OBSE docs. Now that I know it is a type of loop the description of that array command may "say" more to me.
User avatar
Laura Simmonds
 
Posts: 3435
Joined: Wed Aug 16, 2006 10:27 pm

Post » Tue Dec 06, 2011 11:53 am

oh for god sake... wow ...thanks TheNiceOne!

But It was not the indenting that was my issue it was that I did into know FOREACH was a type of loop.

mmmm..... I need to re-read the description of FOREACH in the OBSE docs. Now that I know it is a type of loop the description of that array command may "say" more to me.
Ok, then maybe this can make it a bit clearer:

	ForEach TargetRefArray <- ListOfActors		Let Target := TargetRefArray["Value"]		...	Loop


		let i := 0	While i < ar_Size ListOfActors		Let Target := ListOfActors[i]		...		let i := i + 1	Loop

Here you have two loops that are functionally identical. The inner workings are surely a bit different, and I would guess the former is possibly slightly faster, but they do exactly the same for you - both loops through all elements in ListOfActors and assigns the nth element to Target for each turn in the loop.
User avatar
Princess Johnson
 
Posts: 3435
Joined: Wed Feb 07, 2007 5:44 pm

Post » Tue Dec 06, 2011 7:18 pm

Oh...well thanks TheNiceOne

But your first explanation was exactly what I needed to know I was just mussing that I should now read the docs again about the FOREACH command armed with the explanation you gave me. Sometimes one concept understood opens avenues to many others even in text that has already been read over once before.
User avatar
Everardo Montano
 
Posts: 3373
Joined: Mon Dec 03, 2007 4:23 am


Return to IV - Oblivion