Hi SolarPortal,
Now I'm totally confused
In the API docs it says to use:
- Code: Select all
void Basic_Events::onClick ( int object_ID )
but you have said to use the following:
- Code: Select all
the onClick() event doesn't pass any arguments and is called on the object you are clicking
I have tried both ways, and there is no difference, except that I can't use
- Code: Select all
entity.getPosition ( obj )
anymore as "obj" is always set to zero.
Anyway, my code is as follows:
- Code: Select all
function onMouseDown ( nBtn, nX, nY )
-- nBtn = 1 - Left Click
-- nBtn = 2 - Right Click
sky.setVar ( "nMouseBtn", nBtn );
game.clickObject ( 0 );
end
then in boardModel:
- Code: Select all
obj = 0; -- | Define a variable for our object ID
nBtn = 0;
function onClick ( obj )
sky.lprint("obj = " .. obj);
nBtn = sky.getVar ( "nMouseBtn" );
sky.lprint("nBtn = " .. nBtn);
if ( nBtn == "1" ) then
sky.lprint("SPAWN");
nLocX, nLocY, nLocZ = entity.getPosition ( obj );
id = entity.spawn ( "altar", nLocX, 1, nLocZ, 0.01, 0.01, 0.01 );
entity.addScript ( id, "/playerModel.lua" )
end
end
Then, in playerModel:
- Code: Select all
obj = 0; -- | Define a variable for our object ID
nBtn = 0;
function onClick ( obj )
nBtn = sky.getVar ( "nMouseBtn" );
sky.lprint("nBtn = " .. nBtn );
sky.lprint("obj = " .. obj );
if ( nBtn == "2" ) then
sky.lprint("DELETE");
entity.delete( obj );
end
end
Basically, I create the Playing Board using boardModels, and then place the playing pieces on top, using playerModels.
my log looks like this from placing, and deleting, 2 models:
obj = 125
nBtn = 1
SPAWN
obj = 125
nBtn = 1
SPAWN
obj = 126
nBtn = 1
SPAWN
obj = 126
nBtn = 1
SPAWN
nBtn = 2
obj = 197
DELETE
nBtn = 2
obj = 198
DELETE
nBtn = 2
obj = 199
DELETE
nBtn = 2
obj = 200
DELETE
My guess is that the raycast is seeing both models, but that wouldn't explain the fact that it's spawning 2 playerModels each time??
Edit: If you have an ordinary mouse like us lol
, have you tried to see if that has the same issue to help rule out the software as faulty.
I do have another mouse somewhere, I'll have to see if I can track it down
Thanks for the help so far.
Regards
Shando