Jump to content

destroyElement having problems


|H|TiTanium

Recommended Posts

Well, it's simple but I'm not an expert, basically when player click on a Row of gridlist, a Ped should spawn, and if he changes the row ( clicks on another one ) the previous Ped should get deleted and a new one get created.

What is happening wrong ? The Ped is created, but everytime I click on another row, The previous Ped keeps there, instead of being destroyed. What is wrong ? I need it like this:

When GUI opens, I click on the first Row to get a preview of the Ped, when I click on another Row, the previous Ped should get deleted and the new one should get into my preview. But it's not what is happening.

Here is the thing which is supposed to do the job ( at least in my mind )

function gridClick ( state, absoluteX, absoluteY) 
        local campos = guiGridListGetItemText ( myGridList, guiGridListGetSelectedItem ( myGridList ), 1 ) 
        if campos == "Tiger" then 
        local tigreprev = createPed( 40, 2144.87671, -1177.68799, 23.82031 ) 
        destroyElement(panteraprev) 
        destroyElement(pastorprev) 
        destroyElement(rotprev) 
        destroyElement(loboprev) 
        destroyElement(foxprev) 
    end 
        if campos == "Panther" then 
        local panteraprev = createPed( 44, 2144.87671, -1177.68799, 23.82031 ) 
        destroyElement(tigreprev) 
        destroyElement(pastorprev) 
        destroyElement(rotprev) 
        destroyElement(loboprev) 
        destroyElement(foxprev) 
    end 
        if campos == "Dog German Shepherd" then 
        local pastorprev = createPed( 46, 2144.87671, -1177.68799, 23.82031 ) 
        destroyElement(panteraprev) 
        destroyElement(tigreprev) 
        destroyElement(rotprev) 
        destroyElement(loboprev) 
        destroyElement(foxprev) 
    end 
        if campos == "Dog Rottweiler" then 
        local rotprev = createPed( 49, 2144.87671, -1177.68799, 23.82031 ) 
        destroyElement(panteraprev) 
        destroyElement(pastorprev) 
        destroyElement(tigreprev) 
        destroyElement(loboprev) 
        destroyElement(foxprev) 
    end 
        if campos == "Wolf" then 
        local loboprev = createPed( 47, 2144.87671, -1177.68799, 23.82031 ) 
        destroyElement(panteraprev) 
        destroyElement(pastorprev) 
        destroyElement(rotprev) 
        destroyElement(tigreprev) 
        destroyElement(foxprev) 
    end 
        if campos == "Fox" then 
        local foxprev = createPed( 48, 2144.87671, -1177.68799, 23.82031 ) 
        destroyElement(panteraprev) 
        destroyElement(pastorprev) 
        destroyElement(rotprev) 
        destroyElement(loboprev) 
        destroyElement(tigreprev) 
    end 
end 
addEventHandler ("onClientGUIClick", myGridList, gridClick) 

Link to comment

I'm getting a debugscript error, it says Bad 'element' pointer @ 'destroyElement'(1)

And it says to every line where you find destroyElement.

I made what you've told me to, and now I got this :

function gridClick ( state, absoluteX, absoluteY) 
        local campos = guiGridListGetItemText ( myGridList, guiGridListGetSelectedItem ( myGridList ), 1 ) 
        if campos == "Tiger" then 
        tigreprev = createPed( 40, 2144.87671, -1177.68799, 23.82031 ) 
        destroyElement(panteraprev) 
        destroyElement(pastorprev) 
        destroyElement(rotprev) 
        destroyElement(loboprev) 
        destroyElement(foxprev) 
    end 
        if campos == "Panther" then 
        panteraprev = createPed( 44, 2144.87671, -1177.68799, 23.82031 ) 
        destroyElement(tigreprev) 
        destroyElement(pastorprev) 
        destroyElement(rotprev) 
        destroyElement(loboprev) 
        destroyElement(foxprev) 
    end 
        if campos == "Dog German Shepherd" then 
        pastorprev = createPed( 46, 2144.87671, -1177.68799, 23.82031 ) 
        destroyElement(panteraprev) 
        destroyElement(tigreprev) 
        destroyElement(rotprev) 
        destroyElement(loboprev) 
        destroyElement(foxprev) 
    end 
        if campos == "Dog Rottweiler" then 
        rotprev = createPed( 49, 2144.87671, -1177.68799, 23.82031 ) 
        destroyElement(panteraprev) 
        destroyElement(pastorprev) 
        destroyElement(tigreprev) 
        destroyElement(loboprev) 
        destroyElement(foxprev) 
    end 
        if campos == "Wolf" then 
        loboprev = createPed( 47, 2144.87671, -1177.68799, 23.82031 ) 
        destroyElement(panteraprev) 
        destroyElement(pastorprev) 
        destroyElement(rotprev) 
        destroyElement(tigreprev) 
        destroyElement(foxprev) 
    end 
        if campos == "Fox" then 
        foxprev = createPed( 48, 2144.87671, -1177.68799, 23.82031 ) 
        destroyElement(panteraprev) 
        destroyElement(pastorprev) 
        destroyElement(rotprev) 
        destroyElement(loboprev) 
        destroyElement(tigreprev) 
    end 
end 
addEventHandler ("onClientGUIClick", myGridList, gridClick) 

It works fine, but there are those debug messages, saying that there is something wrong on each destroyElement...

I get "Bad 'element' pointer @ 'destroyElement'(1)" everytime I change between rows

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...