lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I find this quite interesting, but it's not easy to answer any of your questions without access to your code (current api) without jumping in and develop the whole thing for you.

I'd suggest you think over your questions and rephrase them into a more thecnical nature as "how do I make my script call a function in C" (after doing some research on the topic), etc.

API-wise I'd recommend you expose functions to declare platforms (with properties, like waypoints and what not). This way you set the rules in your current application (in C++), but get all data from a script (lua).

Example exposed api (C-side left as exercise :)

create_platform( input: table with options ) output: platform object

oh.. one function was all I could come up with for starters.. ;)

Example usage:

local a_platform = create_platform{
	name = "My first Platform",
	size = { 150, 400 },
	-- optional: pos = { 200, 400, 0 },
	-- if left out, use first waypoint

	waypoints = {
		{ 200, 400, 0, speed = 25, target_waypoint = 3 },
		{ 200, 400, 100, speed = 50, target_waypoint = 1 },
		{ 200, 800, 100, speed = 25, target_waypoint = 2 }
	}
}

-- comments:
This way the waypoints can easily be extended with more features, named and so on.. it all comes down to what you need/want to do. I left out table keys for x, y, and z values for brevity at the expense of clarity.

This is about as far as I can take you (timewise ;)..
Be sure to read up on the Wiki, the PiL book(s) and google around. There's always tons of information out there.

Tip: use some of the tools to bind your c++ code to lua if you don't feel comfortable with the c-to-lua api's.

Cheers,
Andreas


Gary Popov skrev:
Hi guys, I have a question about scripting. I haven't been programming all that long and I've never done any sort of scripting before, so please be gentle with me. I'm also pretty dense. LUA came recommended to me and with the few examples that I've seen, it looked fairly easy to integrate to work with c++ and supposedly fairly fast which is why I chose it.

Anyway, on to the background of the question -- I have a small 3d game to which I want to add some moving platforms. The platforms, for now, I just want to move in fairly linear fashion, but I want to be able to modify them to rotate and so on in the future. Basically, what I want to be able to do is
a) Load the platfoms as part of a level
b) specify the waypoints to which the platforms have to travel
c) Able to specify the speeds and so on between waypoints.
d) Have the platforms stop (or start moving, if stopped) if some trigger was set off.

Furthermore, my question -- What kind of functions should I have in my engine's api, how should I specify the movement/rotation of each platform, and what should my scripts look like.

So for an example... if I had two points, A(0,0,0) and b(10,0,0).. I want..
a) For a platform to move from A to B and take 5 seconds while doing it.
b) For the platform to move from B to A and take 5 seconds while doing it.
c) Repeat that forever.

That's for a simple example, how about something like...
a) Wait for a trigger to be activated/condition set to true
b) Move platform from A to B, take 5 seconds to do it
c) Rotate the platform along the Y axis 360 degrees while moving from A to B. d) Stop at B (until a trigger, perhaps a trigger on the side of the platform on which the person travelled makes it go back)

I'm using Ogre3d and since I'm afraid of threads, everything, rendering, physics, etc, is all done in one thread. If anyone could help me, I'd really appreciate it.

By the way, this is what I have so far -- http://youtube.com/watch?v=1tMedZ6192k

Unfortunately, all of the way points and movement of the platforms is hardcoded into the executible which is .. no good considering I want to be able to load in different levels and also be able to mix-and-match different movements as I pointed out in my examples without having to special case-by-case code for each platform.

Thanks, Gary