lua-users home
lua-l archive

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


This is what I have now, it's very early yet, I just started, and I have
bounced things around trying to get this to work, so it's not what I want in
the end, but here it goes.  I have a state machine, that for each state has
an init, proc, exit, and in my init for the main game state, I call the
following.

mylua_Init();

looks like this at this moment ..

static lua_State * ls;

void mylua_Init()
{
     ls  = lua_open();

     if (NULL == ls) logger("Error Initializing Lua\n");
     else
     {
            logger("Lua Initialized\n");

         lua_baselibopen(ls);
      lua_iolibopen(ls);
      lua_strlibopen(ls);
      lua_mathlibopen(ls);

      lua_register( ls, "addNPC", fl_AddNPC );
      lua_register( ls, "drawstring", fl_DrawString );
      lua_register( ls, "drawnumber", fl_DrawNumber );
      lua_register( ls, "getsceneframe", fl_GetSceneFrame );
      lua_register( ls, "findsetlocation", fl_FindSetLocation );
      lua_register( ls, "keyhit", fl_KeyHit);
      lua_register( ls, "setframe", fl_SetSceneFrame);

}

sorry bout the spacing, outlook has hosed my tabs, then I call

mylua_Load("dam.lua");

which looks like this ...

void mylua_Load(const char *scriptname)
{
 pushandsetdir("scripts");
  lua_dofile(ls, scriptname);
 popdir();
}


dam.lua looks like this(looks familor right? :) )

local Hero = assert( loadfile( "hero.lua" ) )()
local GuardGuy = assert( loadfile( "guard01.lua" ) )()

function createHero()
   return setmetatable( {}, { __index = Hero } )
end

function createGuardGuy()
   return setmetatable( {}, { __index = GuardGuy } )
end

Hero = createHero();

Hero:doSomething()



this works fine but it's not what I want, want I had before was I would
create a hero like this

MOBHuman *thisguy;

thisguy = addchar(0,0,0,actorlist);

then I would load a file like ...

 mylua_Load("heroscript.lua");

then in my main loop I would call

void MOBHuman::Processplayer()
{

            which would update the guys position keyboard input , etc etc.

            I would also call something like mylua_aiprocess(this);

            which looked something like this..

            void mylua_aiprocess(MOBHuman *curactor) {

                    int val;

                   // I stored the current actor passed in so that all the
exposed functions of my game knew which was the current guy

                processingactor = curactor;

                 lua_getglobal(ls, "playerprocess");

                 lua_call(ls, 0, 1);

                // so that when it called something from lua like
here is my old scipt I was using

                function playerprocess()
                     local rvalue = 0

                     if ( keyhit("DIK_SPACE") > 0 ) then
                          --drawstring(-1,30,"hit spacebar")
                          setframe(4099,1) -- framenumber, continue playing
                     end

                     if ( findsetlocation("herostart.mxo",1,0) ) then  -- 
lookfor, setposition, setrotation
                          --drawstring(-1,30,"haha found something")
                        else
                          --drawstring(9,30,"ouch didn't find it")
                     end

                     if ( getsceneframe() > 4100 ) then
                          findsetlocation("dockstart.mxo",1,1)
                          rvalue = 1;
                     end

                        return rvalue
                end

                again this loop was called every frame of my game proc, what
this script did was basically take over all input of my game, and force him
to an object

                that moved in the world until frame 4101 or whatever, then
it would bail out, and I would then not call this function any more, this
was sorta a hack to get something

                working, I planned on revising this, and building from it,
when I started having problems with multiple players, having their own
scripts.  the idea here was that when a function was

                called from lua like this ..



                    int fl_FindSetLocation( lua_State * luaVM ){

                                // I could use processingactor in here, and
it would know from(in theory) when it called from lua, that it was dealing
with processingactor

                                // this is also when I starting having
trouble when I added another guy into the world, and created him and loaded
his file, which has the same function name in lua as the hero guy
playerprocess, since

                                  // I guess there was only one lua_State it
was using the latest playerprocess function for all guys

                   }



Hope this isn't too complicated to understand, not even sure the best ways
to do things in lua, I almost wrote my own scripting language, when I
realized I didn't want to

re-invent the wheel (so to speak), and lua I stumbled across, from a company
who didn't make it  and decided to opensource the whole engine, and source,
and binary to

http://catmother.sourceforge.net/  which I applaud them for, and I have
looked that the stuff they have, but it's a wild goose chase trying to
figure out what was going on.

which sometimes is why I hate c++.  Anyways what I what is a highlevel
scipting language with calls that pretty much do all internal stuff within
c++, and I decide

what to do with the results given back from my game.  In order to do this, I
need to be able to have my game call lua basically every frame (maybe every
few) (for characters and other scritables)

to update the status of things.  Of couse with anything you need a
foundation to build from, and my foundation has termites (at the moment)
thats why I look here for help, I appreciate it.

Tim Ryness




---- Original Message ----- 

From: "Kevin Baca" <lualist@aidiastudios.com>
To: "'Lua list'" <lua@bazar2.conectiva.com.br>
Sent: Sunday, December 07, 2003 9:03 AM
Subject: RE: Simple AI Scripting, Help Me!


> Can you provide a short example script that shows what you want to be
> able to?
>
> It doesn't have to be proper lua, just something that shows what you are
> trying to achieve.
>
> > Thanks for you help, I really appreciate it, my only question
> > now is I need to call a function everyframe to update a dudes
> > position or state (every frame or every 5 or whatever).  Not
> > sure how I would do this with this example below.  How would
> > it tie in with my player class etc.  I don't want to really
> > expose a whole players class (from lua), nothing if I can
> > help it. I want the scripts to be really high level, so
> > anyone could write scripts for it.  I don't want to write the
> > scripts myself, I want to set them up, and hand them off to
> > some else who doesn't have much knowledge of programming (if
> > need be).  So I don't really want it to look like c++, or c
> > (lua does resemble it), just they way one would think
> > enemyclose(), runforcover(), seekhealth(), findescort(), etc
> > etc, and I expose those functions to lua.  If I load this
> > main.lua it will parse the whole thing, and stall my app, I
> > call it from my initfunction of my game, where is before, I
> > called a function to update a guy from c++, everyframe, and
> > returned true when it finished the function .. his goals.
> >
> >
> > Thanks,
> >
>