Jump to content

Problem again


DarthRaff
 Share

Recommended Posts

Hey,

 

I tried this and works perfectly but just in the first object i created. If i try to put more than one object then it doesn't work in the others , just in the first one. But the position, rotation, and all that props works in all the objects. How to do, please, for have the other functions working in all the objects of the same class ?

 

Here is the code:

require("scripts/class")
require("Scripts/constants/engine_const")
local class=CreateClass(...)
function class:InitDialog(grid)
self.super:InitDialog(grid)
--group=grid:AddGroup("type")
--group:AddProperty("tipo",PROPERTY_STRING)
group=grid:AddGroup("estados")
group:AddProperty("initialrot",PROPERTY_INTEGUER)
group:AddProperty("finalrot",PROPERTY_INTEGUER)
--group:AddProperty("rot",PROPERTY_INTEGUER)
group:AddProperty("estado",PROPERTY_STRING)
group:AddProperty("speed",PROPERTY_FLOAT,"-1,1,1")
group:Expand(1)
end
function class:CreateObject(model)
local object = self.super:CreateObject(model)
--object.model:SetKey("tipo","")
object.model:SetKey("initialrot",90)
object.model:SetKey("finalrot",0)
object.model:SetKey("estado","0")
object.model:SetKey("speed",0.6)
function object:UnlockKeys()
 self.estado = self.model:GetKey("estado")
end
function object:Update()
 if KeyHit(KEY_E)==1 then
  self:CheckDoor()
  self.model:SetKey("estado",self.estado)
 end
end
function object:CheckDoor()
 if EntityDistance(fw.main.camera,self.model) < 3 then
  if self.estado == "0" then
   self.estado = "1"
   --self.model:OpenDoor()
  else
   self.estado = "0"
  end
 end
end
end

 

I tried my self but can't find the solution, thank you

Link to comment
Share on other sites

its due to the KeyHit in the update... typically the first one is recognized in the loop and the rest are ignored... if you are trying to make all the doors open/close at the same time, then you have to loop thru all of the doors in that class... if you are just trying to open whatever door you are close to then, the best thing is like i suggested in one of your other posts, is to use the camera/controller to perform a pick on the door and send a message to that door to open/close... and are you sure this script "works perfectly"? you are spelling INTEGER incorrectly... and typically you would want your function to be stated prior to calling the function... so the 'function object:CheckDoor()' should be listed before the 'self:CheckDoor()' called in the 'function object:Update()'

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Well, my intention is to check the door system in the editor without use any game or controller script, but don't know if it's possible. I tried a pick function i found in a script but, don't know if i can do it that way. Actually there is no message sending or received, yet.

 

Is this code correct ?

 if KeyHit(KEY_E)==1 then
  pick=CameraPick(fw.main.camera,Vec3(GraphicsWidth()/2,GraphicsHeight()/2,2.0),0,0)
  if pick~=nil then
   repeat
 if pick.entity:GetClass()==ENTITY_MODEL then
  break
 end
 pick.entity=pick.entity.parent
   until pick.entity==nil
   if pick.entity~=nil then
 --pick.entity:SendMessage("use",controller,0)
 self:CheckDoor()
 self.model:SetKey("estado",self.estado)
   end
  end
 end

 

i' d like to know if it's correct and can do it that way before do the next step, sorry for being bored and thank you.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...