--My Door Trigger Script------------------------
obj = 0 -- | Define a variable for our object ID
moveDoor = false;
direction = 1.2;
y=0;
function onInit(objID)
sky.lprint("\nLUA: Door Open Trigger Demo: ACTIVATED");
doorID = entity.getEntityIDFromTag("Door_7");
bodyID = physics.getBodyID(doorID);
--Sound for door opening and closing...---
sound.setLooped( 0 );
sound.setVolume( .5 );
sound.setSoundFile( "electronicdoor.wav" );
sound.setIsStreamed( 0 );
sound_ID = sound.create2DSound();
end
function onUpdate(timeDelta)
if(moveDoor)then
x,y,z = entity.getPosition( doorID );
y=y+(direction)*timeDelta;
if(y>4)then moveDoor = false;y=4;end
if(y<1.4)then moveDoor = false;y=1.4;end
entity.setPosition( doorID, x, y, z );
physics.setPosition(bodyID, entity.getWorldPosition(doorID));
end
end
function onTrigger_Enter(hitID)
objectHit = entity.getEntityName(hitID);
sky.lprint("LUA: Trigger Event: ENTER! Object Hit= "..objectHit);
direction = 0.9;
sound.play2DSound( sound_ID );
moveDoor = true;
end
function onTrigger_Leave(hitID)
objectHit = entity.getEntityName(hitID);
sky.lprint("LUA: Trigger Event: Exit! Object Hit= "..objectHit);
direction = -0.9;
sound.play2DSound( sound_ID );
moveDoor = true;
end
It also had an interesting error: "Sound file bling.ogg does not exist". I never even tried to reference such a file, so that leaves me confused. Perhaps bling is some kind of default sound?
To add to resources, go to asset manager > navigate to the folder > in the explorer list Right click and go to Resource Management > Add folder to resources. Sometimes clicking on the actual folder will offer to add the resources for you.
-- My Door Trigger Script------
obj = 0 -- | Define a variable for our object ID
moveDoor = false;
direction = 1.2;
y=0;
function onInit(objID)
sky.lprint("\nLUA: Door Open Trigger Demo: ACTIVATED");
doorID = entity.getEntityIDFromTag("Door_1");
bodyID = physics.getBodyID(doorID);
--Sound for door opening and closing... ---
sound.setLooped( 0 );
sound.setVolume( .5);
sound.setSoundFile( "LargeBlowerMotor.wav");
sound.setIsStreamed( 0 );
sound_ID = sound.create2DSound();
end
function onUpdate(timeDelta) -- Update is run once every game cycle
if (moveDoor) then
x,y,z = entity.getPosition( doorID );
y=y+ (direction) *timeDelta;
if(y>4) then moveDoor = false;y=4;end
if(y<1.4) then moveDoor = false;y=1.4;end
entity.setPosition( doorID, x, y, z );
physics.setPosition(bodyID, entity.getWorldPosition(doorID));
end
end
function onTrigger_Enter(hitID)
objectHit = entity.getEntitiyName(hitID);
sky.lprint("LUA: Trigger Event: ENTER! Object Hit = "..objectHit);
direction = 0.9;
sound.play2DSound( sound_ID );
moveDoor = true;
end
function onTrigger_Leave(hitID)
objectHit = entity.getEntitiyName(hitID);
sky.lprint("LUA: Trigger Event: Exit! Object Hit = "..objectHit);
direction = -0.9;
sound.play2DSound( sound_ID );
moveDoor = true;
end
But thank you Mr. Occlusion, for the code drop... once that worked, it was just a matter of replacing it with my functions until it broke again
I typoed getEntityName.
Does this come with any particular benefits?
Oh crap, I just realized that it sounded like was asking about friends with benefits... >_< doh!
Ryder wrote:Thanks everyone...
So I think I can narrow the scope of the issues down a bit:
#1 - Even though my .wav file is in the asset manager, I still get an error message saying that it's not found. But is just being in the asset manager enough? It's not enough for textures... why would it be enough for sounds?
#2 - Trigger function not performing the move. We know the function has been initialized, and that the physics has kicked in (because I can shoot the door).
Here is the code:
- Code: Select all
-- My Door Trigger Script------
obj = 0 -- | Define a variable for our object ID
moveDoor = false;
direction = 1.2;
y=0;
function onInit(objID)
sky.lprint("\nLUA: Door Open Trigger Demo: ACTIVATED");
doorID = entity.getEntityIDFromTag("Door_1");
bodyID = physics.getBodyID(doorID);
--Sound for door opening and closing... ---
sound.setLooped( 0 );
sound.setVolume( .5);
sound.setSoundFile( "LargeBlowerMotor.wav");
sound.setIsStreamed( 0 );
sound_ID = sound.create2DSound();
end
function onUpdate(timeDelta) -- Update is run once every game cycle
if (moveDoor) then
x,y,z = entity.getPosition( doorID );
y=y+ (direction) *timeDelta;
if(y>4) then moveDoor = false;y=4;end
if(y<1.4) then moveDoor = false;y=1.4;end
entity.setPosition( doorID, x, y, z );
physics.setPosition(bodyID, entity.getWorldPosition(doorID));
end
end
function onTrigger_Enter(hitID)
objectHit = entity.getEntitiyName(hitID);
sky.lprint("LUA: Trigger Event: ENTER! Object Hit = "..objectHit);
direction = 0.9;
sound.play2DSound( sound_ID );
moveDoor = true;
end
function onTrigger_Leave(hitID)
objectHit = entity.getEntitiyName(hitID);
sky.lprint("LUA: Trigger Event: Exit! Object Hit = "..objectHit);
direction = -0.9;
sound.play2DSound( sound_ID );
moveDoor = true;
end
Notice that I call my door, "Door_1" (the tag matches), and I specify my sound file. (are file names case sensitive?)
Thank you for your kind help.
Ryder
However, I believe that a microscript and micrograph should be able to share nicely... shouldn't they?
Return to Documents, Tutorials and Videos
Users browsing this forum: No registered users and 0 guests