Making Loops

Post » Wed Jul 21, 2010 1:11 am

I've been playing with a script requiring a series of do while/repeat until/for loop. I know that FOSE makes this easy with its Label and Goto commands but I was wondering about creating them outside of FOSE. I've been using a combination of timers, globals, script variables and stages. Does anyone else do it this way or is FOSE so tried and true that nobody bothers doing it the hard way. An example of the types of things I'm attempting is:

If Var == A
Loop 1
While Var != x ;break
Elseif Var == B
Loop 2
While Var != y ;break
Elseif Var == C
Loop 3
While Var != z ;break
User avatar
Len swann
 
Posts: 3466
Joined: Mon Jun 18, 2007 5:02 pm

Post » Tue Jul 20, 2010 10:56 pm

Why are you trying to make life purposely difficult for yourself?

The standard geck scripting just doesn't provide that kind of functionality...
User avatar
lolly13
 
Posts: 3349
Joined: Tue Jul 25, 2006 11:36 am

Post » Tue Jul 20, 2010 8:03 pm

Real loops cannot be created without FOSE. The closest you can really get is treating each execution of a script as an iteration in a loop, but for most things that actually require loops this isn't fast enough. Loops created using FOSE run to completion within a single script execution.

Cipscis
User avatar
Lifee Mccaslin
 
Posts: 3369
Joined: Fri Jun 01, 2007 1:03 am

Post » Tue Jul 20, 2010 1:50 pm

Why are you trying to make life purposely difficult for yourself?


Well the "excuse" answer would be so that the mod could be used by people who don't use FOSE for whatever reason. The real answer would be a mild case of OCD. (I know I can make this work if I just spend a little more time on it!)

Thank you Cipscis for defining the actual differences between a true loop and my pseudo-loops.
User avatar
Raymond J. Ramirez
 
Posts: 3390
Joined: Sun Oct 14, 2007 8:28 am

Post » Wed Jul 21, 2010 2:43 am

Well the "excuse" answer would be so that the mod could be used by people who don't use FOSE for whatever reason. The real answer would be a mild case of OCD. (I know I can make this work if I just spend a little more time on it!)

Thank you Cipscis for defining the actual differences between a true loop and my pseudo-loops.


Use fose... you know you want to! :P
User avatar
LittleMiss
 
Posts: 3412
Joined: Wed Nov 29, 2006 6:22 am

Post » Tue Jul 20, 2010 10:46 pm

Use fose... you know you want to! :P

And is totally unnecessary for most purposes. :)
User avatar
Megan Stabler
 
Posts: 3420
Joined: Mon Sep 18, 2006 2:03 pm

Post » Wed Jul 21, 2010 12:23 am

And is totally unnecessary for most purposes. :)


It's statements like that that drive my afore mentioned OCD. :biglaugh:
User avatar
Arnold Wet
 
Posts: 3353
Joined: Fri Jul 07, 2006 10:32 am

Post » Tue Jul 20, 2010 12:18 pm

You could attempt to kludge one up using activators if you are desperate - The activate command can be used recursively to create (the semblance of) a loop.
User avatar
Melis Hristina
 
Posts: 3509
Joined: Sat Jun 17, 2006 10:36 pm

Post » Wed Jul 21, 2010 1:35 am

And is totally unnecessary for most purposes. :)

Agreed. With smart use of variables and conditionals, the GameMode block is quite fast enough to accomplish this no problem.
User avatar
Ebou Suso
 
Posts: 3604
Joined: Thu May 03, 2007 5:28 am

Post » Tue Jul 20, 2010 11:36 am

Would performance become an issue when using a non FOSE loop like script vs an actual FOSE loop? What if there were 100+ loops running at once?

I guess at this point that's more a theoretical knowledge rather than "I need to know right away".
User avatar
Tessa Mullins
 
Posts: 3354
Joined: Mon Oct 22, 2007 5:17 am

Post » Wed Jul 21, 2010 2:07 am

If there's lots of gamemode blocks running at once then the game defers some and doesn't process them all every frame- and when it does, it usually starts processing the newer scripts first then works it's way back. This makes it spectacularly unsuitable for some uses- for example, a laser tracker placing a scripted item where it's pointing simply doesn't work but placing nonscripted items and finding them with FOSE ref walking has no problems.
User avatar
Guy Pearce
 
Posts: 3499
Joined: Sun May 20, 2007 3:08 pm

Post » Tue Jul 20, 2010 4:31 pm

I have managed to effect a loop in-game using an actor effect. It loops your code once per frame unless you slow it down on purpose.

It is not a shortcut in code that will perform a loop within a single frame of code. It's a batch of code that will loop, but once per frame, while in gamemode. its not like you can throw it in a quest script and rock with it.

You set the effect to have a duration. Duration is kinda meaningless for what you are doing, but theoretically the max that the thing will ever be allowed to run. Just set it to something longer than you really want it to live for.

Your actor effect is a archtype - script, so you get to write a script for it.

You set up your initial variable values in the scripteffectstart block. Then you use the fact that the scripteffectupdate will run every frame to create a loop behavior.

I believe it will run the scripteffectupdate block twice in the first frame that scripteffectstart runs, and then, it will run the scripeffectupdate once per frame, until the duration is exceeded, or, you break out of it.

There are some caviats to watch out for, but anyway.

A simple example would look like this.

scn MyLoopyEffectScriptshort counterbegin scripteffectstartset counter to 1; I always start at some value other than 0endbegin scripteffectupdateif counter == 20	 set counter to 0	 dispel MyHappyActorEffect;to be on the safe side	 return; return should cancel the effect but I use above too, just in case endifif counter;always test for some value of counter	 set counter to counter + 1;the code you sorta want to repeat would be here, I put a one-liner below	  showmessage defaultdebugmsg counterendifend


I felt like it was possible to get extra executions of the scripteffectupdate block sometimes. That's why I always put that conditional in for "counter" being nonzero for the code I want to do work. in case it tries to run extra times.
User avatar
Cesar Gomez
 
Posts: 3344
Joined: Thu Aug 02, 2007 11:06 am

Post » Tue Jul 20, 2010 9:50 pm

TBF you could get that a bit more simply.
if(counter)   set counter to counter -1  ;do thingselse   dispel MySpell   returnendif

In an update block, with counter being set to the max number of loops, will do the same thing but more efficiently and automatically handling any loops of 0.
User avatar
JUan Martinez
 
Posts: 3552
Joined: Tue Oct 16, 2007 7:12 am

Post » Tue Jul 20, 2010 10:51 pm

Here is how I use the thing above - - -

I call it from a quest script like this:

scn My HappyQuestScriptshort Subroutinebegin GAMEMODEif subroutine	 set subroutine to subroutine + 1	 if subroutine == 10;the actoreffect died and never came back for god knows what reason, so just resume normal processing		  set subroutine to 0		  showmessage YourEffectJustBrokeKTHX	 endifendifif Subroutine == 0	if MyNPCRef.didsomething == 1		  set Subroutine to 1		  MyNPCref.cios MyHappyActorEffect	 endifendifEND




and then the effect script is like this:



scn MyLoopyEffectScriptshort counterbegin scripteffectstartset counter to 1; I always start at some value other than 0endbegin scripteffectupdateif counter == 20	 set counter to 0	 set MyHappyQuest.Subroutine to 0;<---------- tells the quest script it's done	 dispel MyHappyActorEffect;to be on the safe side	 return; return should cancel the effect but I use above too, just in caseendifif counter;always test for some value of counter	 set counter to counter + 1;the code you sorta want to repeat would be here, I put a one-liner below	  showmessage defaultdebugmsg counterendifend

User avatar
Assumptah George
 
Posts: 3373
Joined: Wed Sep 13, 2006 9:43 am

Post » Wed Jul 21, 2010 1:15 am

TBF you could get that a bit more simply.
if(counter)   set counter to counter -1;do thingselse   dispel MySpell   returnendif

In an update block, with counter being set to the max number of loops, will do the same thing but more efficiently and automatically handling any loops of 0.


Yeah you sure could if it's what you need - I just wanted to show the mechanism mainly.

(The way I personally had to use this doesn't even resemble a loop, it's a turn-taking thing sorta, with one piece of code getting executed on each pass, and each piece that gets executed sets its own variable which disallows it from being run twice, and the total number of code blocks that needs to run is set within scripteffectstart... beh. )
User avatar
asako
 
Posts: 3296
Joined: Wed Oct 04, 2006 7:16 am


Return to Fallout 3