enigma-devel
[Top][All Lists]
Advanced

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

Re: [Enigma-devel] Call a function with current x/y coordinates


From: Petr Machata
Subject: Re: [Enigma-devel] Call a function with current x/y coordinates
Date: Sun, 05 Oct 2003 19:14:54 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3; MultiZilla v1.3.1 (c)) Gecko/20030312

Michi Hostettler wrote:
hi,

is it possible to get the current x and y coordinates for a cell? for
example:

Require("levels/ant.lua")
function file_oxyd(x,y,f)
    oxyd_default_flavor=f
    oxyd(x,y)
end

function GTarget(x,y) <--x and y should be the cordinates of the cell
print("gt:",tostring(x))
print("gt:",tostring(y))
if (x==1) and (y==0) then retval="laser1" <-- Only if current cell is the
cell with the red marked !
return (retval)
end

function GAction(x,y) <--x and y should be the cordinates of the cell
print("ga:",tostring(x))
print("ga:",tostring(y))
if (x==1) and (y==0) then retval="laser1" <-- Only if current cell is the
cell with the red marked !
return (retval)
end

cells["!"]=cell{stone={"st-switch", {action=GAction,target=GTarget}}} <-- if
a cell is ! then it should call GAction and GTarget with this cell's
coordinates.
cells["."]=cell{stone={"st-laser-w", {on=1,name="laser1"}}}


As to my best knowledge, action and target have to be strings. Enigma then takes an object with the name <target> and sends a message <action> to it. No coordinates are transferred.

If you want to call a 'GTarget' each time you press a button, use this:
 action="callback"
 target="GTarget"
However, GTarget will get only one argument -- a state of button (1 or 0, afaik).

You could somehow utilize CELL's parent handling, for example this:
 cells["!"]=cell{parent={GTarget}}
will call function GTarget for each cell, that you marked with '!', and it will pass a coordinates also. But it will be done once only, at the moment when you call 'create_world_by_map'.

Actually, there is at least one way how to make what you want. But it involves rather hardcore LUA hacking and definitely it won't be nice code.


michi


Petr Machata







reply via email to

[Prev in Thread] Current Thread [Next in Thread]