Jump to content

  • Log In with Google      Sign In   
  • Create Account

Separate lua scripts for each scene


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 NSDuo   Members   -  Reputation: 270

Like
0Likes
Like

Posted 05 December 2011 - 02:32 PM

I have a series of nodes used to organize various events into scenes within my engine.
However, it has recently occurred to me that I have no idea how to properly program logic for these scenes individually.

The only ways I know I could do this is:
Many "if" or "case" statements
-- this would be in lua
if level1 then
	level1logic()
elseif level2 then
	level2logic()
elseif level3 then
	level3logic()
end
-- and so on and so on

I have a strange gut feeling that this method might be too slow and confusing.

Scenes calling lua functions
// this would be in C++

scene::callLogic()
{
	luaCall("functionName");
}

// and then

currentScene->callLogic();
This is the method I like the most, but I have a feeling it won't work

These are the two methods for scripting logic that I was able to come up with, but I'm not sure which one is the best, or even if they're the correct approach at all.
I would really appreciate the help.

Macbook Pro 2.66Ghz dual core, 4GB ram, 512MB vram, MacOSX 9.1, Windows 8.1
Xcode 5.0.2, C++, lua


Sponsor:

#2 crancran   Members   -  Reputation: 416

Like
0Likes
Like

Posted 06 December 2011 - 10:53 AM

It isn't uncommon in game frameworks to have a scripting system/manager class that on a pre-defined interval (every game loop or every X frames or every X milliseconds) the update() method on the script manager class is executed which iterates each active script and runs the script's update method (or some variant thereof). This is a great way to write game logic that you want to test out and prototype too and if you find the performance isn't ideal, you can then transpose that logic to C++ later if you find it needs to be faster. But the concept allows you rapidly prototype features which is a huge advantage.

#3 NSDuo   Members   -  Reputation: 270

Like
0Likes
Like

Posted 06 December 2011 - 09:35 PM

It isn't uncommon in game frameworks to have a scripting system/manager class that on a pre-defined interval (every game loop or every X frames or every X milliseconds) the update() method on the script manager class is executed which iterates each active script and runs the script's update method (or some variant thereof). This is a great way to write game logic that you want to test out and prototype too and if you find the performance isn't ideal, you can then transpose that logic to C++ later if you find it needs to be faster. But the concept allows you rapidly prototype features which is a huge advantage.


That sounds somewhat like the second method.
When you say "each active script", what exactly does that mean? Do you mean a ".lua" file for every scene?

Macbook Pro 2.66Ghz dual core, 4GB ram, 512MB vram, MacOSX 9.1, Windows 8.1
Xcode 5.0.2, C++, lua


#4 swiftcoder   Senior Moderators   -  Reputation: 10367

Like
0Likes
Like

Posted 10 December 2011 - 06:21 PM

When you say "each active script", what exactly does that mean? Do you mean a ".lua" file for every scene?

Usually it is more like a '.lua' script for every object, plus a '.lua' script for every scene. The idea is to move as much of the behaviour of each object as possible into the object script, so that your scene script has less to do - it really just needs to setup the objects, and check for the ending condition.

Consider a game of PacMan: each level might have a script to spawn the player, enemies and dots, as well as to check for the victory/loss condition (eat all dots/be eaten). Each type of enemy would also have its own script to provide it's behaviour - movement, strategy, etc.

Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS