Spherical forums

Sphere Development => Sphere Support => Script Support => Topic started by: Harry Bo21 on May 15, 2013, 09:11:16 pm

Title: Require/Evaluate Script
Post by: Harry Bo21 on May 15, 2013, 09:11:16 pm
Why would you use evaluate if you have require? surely require is just the more efficient equivalent right?
Title: Re: Require/Evaluate Script
Post by: N E O on May 16, 2013, 01:47:04 am
I think the main difference between the two is that require would abort out if it couldn't include it, while evaluate wouldn't.

This just had me realize there's no equivalent to include_once/require_once in Sphere's API. Hmm.
Title: Re: Require/Evaluate Script
Post by: Radnen on May 16, 2013, 02:12:44 am
RequireScript was supposed to only be required once. But I don't think that's true.
Title: Re: Require/Evaluate Script
Post by: Fat Cerberus on May 16, 2013, 02:43:28 am
RequireScript is like #pragma once in C++, if the same script has already been included, it won't evaluate it again. This is so you can put your dependent scripts at the top of each of your classes without worrying about the same script being eval'd again and potentially overwriting globals in the process.
Title: Re: Require/Evaluate Script
Post by: Flying Jester on May 16, 2013, 04:59:31 pm
I'm not sure it actually works that way, though. I seem to recall having issues with RequireScript running the script even if it was previously included.
Title: Re: Require/Evaluate Script
Post by: Fat Cerberus on May 16, 2013, 05:08:31 pm
Odd, I use it all over Specs and never had an issue.  Of course I'm using Sphere 1.5 still, maybe there was a regression in 1.6?
Title: Re: Require/Evaluate Script
Post by: alpha123 on May 17, 2013, 01:10:03 am
From when I was working in the C++ source more often doing Sphere 1.7, RequireScript() is definitely supposed to only load the script once, while EvaluateScript() will load the script every time it is called. However, I did have an issue recently that suggested it might not actually work. :P
So really I'm not quite sure. Given that I don't think anybody relies upon RequireScript bugs, that would be a nice fix for TurboSphere.