Advertisement

Multiple scripts with the same function names?

Started by August 04, 2018 11:49 PM
3 comments, last by Miss 6 years, 3 months ago

I just started using Angelscript, and am misunderstanding how exactly to set up everything.

One of my confusions is, suppose I want a script for each area, with maybe an interface like this:


void onLoad()
{
   //...unique initialization logic for this area...
}

void onTick()
{
   //...unique update code for this area...
}

How do I prevent the AreaA.as script's onLoad() function signature from conflicting with AreaB.as script's onLoad()? How do I call a specific one's function?

Would I make each *area* have a separate *module*? That doesn't sound right.

Each area would provide *different* logic in each Area's function, so it doesn't seem like it'd make sense to make Area a class, I think.

 

 

I suppose I could just have an AreaA_OnLoad.as script, when I load the script, just wrap it in void AreaA_OnLoad() {  <file code>  } , like the ExecuteString() utility does.

Advertisement

There are multiple solutions. Which works best for you will depend on your preferences and overall design of your engine.

If each "area" is supposed to be independent, and loaded dynamically as the player enters the areas, then ideally each would be loaded into separate modules, in which case there is no problem with them having the same symbol names. 

If the "areas" are not independent and all loaded together at start up, then you can put them all into the same module, in which case you need to have a way to separate the symbol names. One way is using the prefix like you already thought of. Another is to use script classes to represent each "area", and finally you can also use namespaces.

 

 

 

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

In your case I would recommend using modules, that way you get to keep the syntax you want.

This topic is closed to new replies.

Advertisement