What's the Difference

Post » Thu Nov 05, 2009 8:24 am

What's the difference between:

begin drumif ( MenuMode == 1 )	Returnendifif ( OnActivate == 0 )	ReturnendifPlaySound3D "drum"End


and

begin drumif ( MenuMode == 1 )	Returnendifif ( OnActivate == 1 )	PlaySound3D "drum"endifEnd


Is the first one more efficient somehow, or is it a less efficient convoluted 'double negative'. (Bethesda seems to use both styles if you look at, say, shrineFelms vs shrineGhostgate).
User avatar
Agnieszka Bak
 
Posts: 3540
Joined: Fri Jun 16, 2006 4:15 pm

Post » Thu Nov 05, 2009 1:27 am

I think the first method is more efficient, actually, because it just keeps on returning if the conditions aren't true. The second one, on the other hand, will just keep on checking and checking until the condition is true. I mean, it's not really a big difference performance wise, not anything that would ever be noticeable, I don't think.
User avatar
TOYA toys
 
Posts: 3455
Joined: Sat Jan 13, 2007 4:22 am

Post » Thu Nov 05, 2009 4:06 am

The second one, on the other hand, will just keep on checking and checking until the condition is true.


Is that in fact what happens? I'd always assumed that OnActivate meant nothing would happen (no script processing) until you actually dealt with the object. The logical extension is to ask, if not, then why isn't EVERYTHING (scripted doors etc.) written the first way? As it is, if ( onactivate == 0 ) seems to apply mostly to shrines and 6th House bells. I think you're right that it probably wouldn't make much difference. Still, I'm curious.
User avatar
M!KkI
 
Posts: 3401
Joined: Sun Jul 16, 2006 7:50 am

Post » Thu Nov 05, 2009 11:40 am

I'd always assumed that OnActivate meant nothing would happen (no script processing) until you actually dealt with the object.

Every script currently loaded (global script, script on item in inventory, script attached to object in currently loaded cells) is run once per frame. In either of those scripts above, the value of onActivate will be checked every frame unless MenuMode == 1.

Which way a script is written will come down to the preferences of the script writer. In simple terms you want to run the fewest instructions required at any given time, and in terms of the two scripts shown I doubt there would be any difference between them (the second would give a small space saving). You could rip out the compiled scripts, and assuming you know the op codes and the clock cycles required to run them, calculate the most efficient, but I still think any differences will be inconsequential.

Also bear in mind that readability can sometimes be at least as important as script efficiency.

Personally, I would write it the second way since I consider the second return in the first script redundant.
User avatar
Sophie Louise Edge
 
Posts: 3461
Joined: Sat Oct 21, 2006 7:09 pm

Post » Thu Nov 05, 2009 11:08 am

Every script currently loaded (global script, script on item in inventory, script attached to object in currently loaded cells) is run once per frame. In either of those scripts above, the value of onactivate will be checked every frame unless MenuMode == 1.

Well, well. Okay.

Personally, I would write it the second way since I consider the second return in the first script redundant.

That's what I was inferring.
Well put, folks. Thanks.
User avatar
OnlyDumazzapplyhere
 
Posts: 3445
Joined: Wed Jan 24, 2007 12:43 am


Return to III - Morrowind