"invalid loop block structure"?

Post » Sat May 28, 2011 5:10 pm

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
Setal Vara
 
Posts: 3390
Joined: Thu Nov 16, 2006 1:24 pm

Post » Sat May 28, 2011 6:39 pm

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
Romy Welsch
 
Posts: 3329
Joined: Wed Apr 25, 2007 10:36 pm

Post » Sat May 28, 2011 1:12 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
BaNK.RoLL
 
Posts: 3451
Joined: Sun Nov 18, 2007 3:55 pm

Post » Sat May 28, 2011 2:53 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.
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
Fiori Pra
 
Posts: 3446
Joined: Thu Mar 15, 2007 12:30 pm

Post » Sat May 28, 2011 12:45 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
Miss Hayley
 
Posts: 3414
Joined: Tue Jun 27, 2006 2:31 am


Return to IV - Oblivion