lua-users home
lua-l archive

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


Chris wrote:
> 
> Hello, I'm trying to figure if I could use LUA as a scripting language for a
> part time game project.
/snip
> Here is the pseudo language I would need (this is only an example, a draft,
> you name it) :
> 
> Sub Init
> RunGoal("JohnAtWork1")
> EndSub
> 
> Goal John_AtWork1
> Conditions
> TimeBetween(9,22)
> Not GoalRunning(John_AtWork2)
> Prerequisite
> MoveTo(X,Y) // Point1 into the inn
> Actions
> RandomNoise()
> Wait(30)


Well, if you are willing to slightly modify your syntax, 
then this will work with tables. (This is untested lua 5 code)

Goals = {};
GoalNow = nil;
GoalInput = nil;

function Goal(name)
   GoalNow = name;
   Goals[GoalNow] = {};  
end

function Conditions(lst)
  Goals[GoalNow]["Conditions"] = lst;
end

function Prerequisite(lst)
  Goals[GoalNow]["Prerequisite"] = lst;
end

function Actions(lst)
  Goals[GoalNow]["Actions"] = lst;
end

function FUN(s)
return function() return dostring(s) end
end

-- Now we can do the following:

Goal "John_AtWork1"
Conditions {
 FUN "TimeBetween(9,22)",
 FUN "GoalNotRunning(John_AtWork2)",
}
Prerequisites {
 FUN "Moveto(X,Y)",
}

Actions {
 FUN "Randomnoise()",
 FUN "Wait(30)",
}

Now, you can use the Goals table as a repository for all existing 
goals, and you can call the functions you need when you need them.
With a bit more clevernes, you'll be able to make the syntax even more 
to what you had in mind.



-- 
"No one knows true heroes, for they speak not of their greatness." -- 
Daniel Remar.
Björn De Meyer 
bjorn.demeyer@pandora.be