Jump to content

Bad argument @ "getElementByID" | Switch two functions


Recommended Posts

Hello,

I'm working on a lighting signal system. But I have a little problem with function "getElementByID".

My system work like that :

- I make a command to create/destroy a big pannel which the lights will be attached to.

- I make a command to create lights, attach them to the pannel and let them blink.

So, here is the script (i removed some attachElements and createMarker because there are a lot of lights)

  
--create panel  
function createBali( player, cmd ) 
    local balisage = getPedOccupiedVehicle(player) 
    local x,y,z = getElementPosition( balisage ) 
    balis = createObject(2789, x, y, z) 
    attachElements(balis,balisage,0,-5.75,1.5,0,90) 
end 
--delete panel 
function deleteBali( player, cmd ) 
    destroyElement(balis) 
end 
addCommandHandler ( "balisage1", createBali) 
addCommandHandler ( "balisage10", deleteBali) 
  
  
  
--right direction 
function lightsOpen1 ( player, cmd ) 
    balis = getElementByID(balis) 
    fld1 = createMarker ( 0,0,0,"corona",0.2,255,165,0) 
    -- and a lot of same code 
     
    attachElements ( fld1, balis, -1.5, -0.1, -1 ) 
    -- and a lot of same code 
end 
addCommandHandler ( "flechedroite", lightsOpen1 ) 
  

As you can see at line 20, I put a getElementByID because without that, I have a "bad argument @ attachElements"

And here start the problem... I have also a bad argument but at getElementByID .

---------------------------------------------------

Second question : How can I made the lights to blink like if I do:

-createMarker

-destroyElement

-createMarker

-destroyElement

-......

-......

with a blink speed of 250ms. ( In mind that I have 17 markers)

Thanks in advance,

dragonofdark

Link to comment

element ID is a string and it is optional.

"balis" in your script is already an element (unless you redefine balis variable somewhere), the one you created with createObject. so you dont need getElementByID.

i'm not sure if attachElements will work correctly with the element that is already attached to something, never tried that.

Link to comment

try this for getPedOccupiedVehicle error

  
--create panel 
function createBali( player, cmd ) 
    local balisage = getPedOccupiedVehicle(source) 
    local x,y,z = getElementPosition( balisage ) 
    balis = createObject(2789, x, y, z) 
    attachElements(balis,balisage,0,-5.75,1.5,0,90) 
end 
--delete panel 
function deleteBali( player, cmd ) 
    destroyElement(balis) 
end 
addCommandHandler ( "balisage1", createBali) 
addCommandHandler ( "balisage10", deleteBali) 
  
  
  
--right direction 
function lightsOpen1 ( player, cmd ) 
    balis = getElementByID(balis) 
    fld1 = createMarker ( 0,0,0,"corona",0.2,255,165,0) 
    -- and a lot of same code 
    
    attachElements ( fld1, balis, -1.5, -0.1, -1 ) 
    -- and a lot of same code 
end 
addCommandHandler ( "flechedroite", lightsOpen1 ) 
  
  
  
  
  
  

Link to comment

Like Aibo said, it's a question if you can attach to elements that are already attached. However from what I've read on the wiki, you CAN do that.

  
function lightsOpen1 ( player, cmd ) 
    fld1 = createMarker ( 0,0,0,"corona",0.2,255,165,0) 
    -- and a lot of same code 
    
    attachElements ( fld1, balis, -1.5, -0.1, -1 ) 
    -- and a lot of same code 
end 
addCommandHandler ( "flechedroite", lightsOpen1 ) 
  

If that doesn't work, try to attach the marker to the vehicle instead of the panel.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...