Skip to main content

News

Topic: Require/Evaluate Script (Read 2614 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
Require/Evaluate Script
Why would you use evaluate if you have require? surely require is just the more efficient equivalent right?

  • N E O
  • [*][*][*][*][*]
  • Administrator
  • Senior Administrator
Re: Require/Evaluate Script
Reply #1
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.

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Require/Evaluate Script
Reply #2
RequireScript was supposed to only be required once. But I don't think that's true.
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: Require/Evaluate Script
Reply #3
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.
miniSphere 5.2.12 - Cell compiler - SSj debugger - thread | on GitHub
For the sake of our continued health I very much hope that Fat Cerberus does not become skilled enough at whatever arcane art it would require to cause computers to spawn enourmous man eating pigs ~Rhuan

Re: Require/Evaluate Script
Reply #4
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.

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: Require/Evaluate Script
Reply #5
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?
miniSphere 5.2.12 - Cell compiler - SSj debugger - thread | on GitHub
For the sake of our continued health I very much hope that Fat Cerberus does not become skilled enough at whatever arcane art it would require to cause computers to spawn enourmous man eating pigs ~Rhuan

Re: Require/Evaluate Script
Reply #6
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.