This is in AGS, yea. Adore is not ready for a real game yet.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menuint lastRoom = -1;
#ifdef USE_LUA
function game_start()
{
int i = 1;
while (i < Game.MouseCursorCount)
{
Mouse.DisableMode(i);
i++;
}
Mouse.Mode = eModeWalkto;
Lua.SetVar("DebugMode", Lua.BoolValue(false));
#ifdef DEBUG
//Debug(4, 1);
Lua.SetVar("DebugMode", Lua.BoolValue(true));
#endif
Lua.RunScript("main.lua");
Lua.Call("FireEvent", Lua.StringValue("game_start"));
}
function on_key_press(eKeyCode keycode)
{
#ifdef DEBUG
if (keycode == eKeyCtrlX)
Debug(3, 0);
#endif
LuaValueList *l = Lua.NewValueList();
l.Add(Lua.StringValue("on_key_press"));
l.Add(Lua.IntValue(keycode));
Lua.Call("FireEvent",l);
}
function on_mouse_click (MouseButton button)
{
LuaValueList *l = Lua.NewValueList();
l.Add(Lua.StringValue("on_mouse_click"));
l.Add(Lua.IntValue(button));
Lua.Call("FireEvent",l);
}
function on_event(EventType ev, int data)
{
LuaValueList *l = Lua.NewValueList();
if (ev == eEventAddInventory) l.Add(Lua.StringValue("AddInventory"));
else if (ev == eEventEnterRoomBeforeFadein) l.Add(Lua.StringValue("EnterRoomBeforeFadein"));
else if (ev == eEventLeaveRoom) l.Add(Lua.StringValue("LeaveRoom"));
else if (ev == eEventGUIMouseDown)
{
GUIControl *gc = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
LuaValueList *lvl = Lua.NewValueList();
if (Mouse.IsButtonDown(eMouseLeft))
{
on_mouse_click(eMouseLeft);
lvl.Add(Lua.IntValue(eMouseLeft));
}
if (Mouse.IsButtonDown(eMouseRight))
{
on_mouse_click(eMouseRight);
lvl.Add(Lua.IntValue(eMouseRight));
}
if (gc == null)
{
GUI *g = GUI.GetAtScreenXY(mouse.x, mouse.y);
if (g != null)
g.LuaMethod("OnClick",lvl);
}
else if(gc.AsButton != null)
{
gc.AsButton.LuaMethod("OnClick",lvl);
}
return;
}
l.Add(Lua.IntValue(data));
Lua.Call("FireEvent",l);
}
function repeatedly_execute_always()
{
Lua.Call("FireEvent", Lua.StringValue("repeatedly_execute_always"));
Lua.Call("FireEvent", Lua.StringValue("late_repeatedly_execute_always"));
Lua.SetVar("Blocked", Lua.BoolValue(true));
}
function repeatedly_execute()
{
if (player.Room != lastRoom)
{
Lua.Call("FireEvent", Lua.StringValue("EnterRoomAfterFadein"));
lastRoom = player.Room;
}
LuaValueList *l = Lua.NewValueList();
l.Add(Lua.StringValue("LeaveEdge"));
if (player.y > Room.BottomEdge)
{
l.Add(Lua.StringValue("bottom"));
Lua.Call("FireEvent", l);
}
else if (player.y < Room.TopEdge)
{
l.Add(Lua.StringValue("top"));
Lua.Call("FireEvent", l);
}
else if (player.x < Room.LeftEdge)
{
l.Add(Lua.StringValue("left"));
Lua.Call("FireEvent", l);
}
else if (player.x > Room.RightEdge)
{
l.Add(Lua.StringValue("right"));
Lua.Call("FireEvent", l);
}
Lua.Call("FireEvent", Lua.StringValue("repeatedly_execute"));
Lua.SetVar("Blocked", Lua.BoolValue(false));
}
function unhandled_event (int what, int type)
{
LuaValueList *l = Lua.NewValueList();
l.Add(Lua.StringValue("unhandled_event"));
l.Add(Lua.IntValue(what));
l.Add(Lua.IntValue(type));
Lua.Call("FireEvent",l);
}
#endif
function dialog_request(int param) {
}
-----------------------------------------------------
--
-- Lua Control Module
--
-- Calin Leafshade
--
-- A module to register global events in lua
--
-----------------------------------------------------
local events =
{
delegates = {},
objects = {}
}
function events:registerObject(obj)
table.insert(self.objects,obj)
end
function events:register(event, priority, callback)
if type(priority) == "function" then
callback = priority
priority = 100
end
local callbacks = self.delegates[event] or {}
self.delegates[event] = callbacks
table.insert(callbacks, {f = callback, priority = priority})
table.sort(callbacks, function(a,b)
return a.priority < b.priority
end)
end
function events:fire(event, ...)
for i,v in ipairs(self.objects) do
if type(v[event]) == "function" then
if v[event](v,...) then break end
end
end
for i,v in ipairs(self.delegates[event] or {}) do
if v.f(...) then break end
end
end
return events
Events = require('interop.lua')
function FireEvent(...) -- this is a global function to allow AGS easier access to it
Events:fire(...)
end
--then you can use the events module like this in any lua file:
Events:register("game_start", function()
aAudio:Play()
end)
--you can also make objects like this:
local myObject = {}
function myObject:repeatedly_execute_always()
-- do this every frame
end
Events:registerObject(myObject)
-- This means that all the events in this object will be run when triggered by interop (if they exist in the object, they dont have to)
Quote from: monkey_05_06 on Mon 05/05/2014 17:24:47
Once I get a build that everyone's generally happy with then I'll dump it all into a single "initial" commit and pull that in instead.)
function hHotspot1_UseInv()
{
if (player.ActiveInventory == iFoo)
{
player.Say("I don't think i should use the foo with that.");
}
else if (player.ActiveInventory == iBar)
{
player.Say("Gee, I shouldnt use the Bar with that just now.");
}
else if (adInfinitum)
{
dieOfBoredom();
}
else
{
player.Say("that doesn't work");
}
}
hHotspot1.UseInv = {
[iFoo] = function() player:Say("I don't think I should use the foo with that") end,
[iBar] = function() player:Say("Gee, I shouldn't really use the bar with that.") end
}
--now call it in your main game code:
local func = hHotspot1.UseInv[player.ActiveInventory] or unhandled -- unhandled is our generic "that doesnt work" function
func() -- call the function
if myValue > 1 then
Billy: Gee, I sure hope myValue was bigger than 1
else
Billy: Lol, myValue.. You cad.
end
By continuing to use this site you agree to the use of cookies. Please visit this page to see exactly how we use these.
Page created in 0.118 seconds with 16 queries.