Jump to content

Lua f*k sh*t


s2sk

Recommended Posts

I MAKE SO


 

setElementData(source, "countCheckpoitBusRoad", 0) -- somewhere in the code



local countCheckpoint = getElementData(player, "countCheckpoitBusRoad") + 1 -- callback hit marker -- AND HERE ERROR

setElementData(player, "countCheckpoitBusRoad", countCheckpoint)

 

AND HAVE "ERROR: attempt to perform arithmetic on a boolean value 'countCheckpoint '"

WHY??? MY SYSTEM-BUS WORK, BUT IN CONSOLE MORE ERROR 

 

 

Link to comment
  • Discord Moderators

I dont know if some1 have noticed it, but it should be countCheckpointBusRoad
 

setElementData(player, "countCheckpoitBusRoad", 0) -- somewhere in the code


local countCheckpoint = getElementData(player, "countCheckpoitBusRoad") -- Why do u store it in elementData, if only the same resource uses it?

setElementData(player, "countCheckpoitBusRoad", countCheckpoint + 1) -- set element's data to the current value + 1

It should be working.
I suppose that the element on which you set the elementData was the problem(changed source to player at line 1)

Edited by Pirulax
Link to comment

OK, I did as you said. you know what now? got error which was not


 

destroyElement(getElementData(player, "elementCheckpointBus"))

local marker = createMarker(busRoad[roadName][countCheckpoint][1], busRoad[roadName][countCheckpoint][2], busRoad[roadName][countCheckpoint][3], "checkpoint", 5.0, 59, 144, 244, 200, player)
    setMarkerTarget(marker, busRoad[roadName][countCheckpoint + 1][1], busRoad[roadName][countCheckpoint + 1][2], busRoad[roadName][countCheckpoint + 1][3])
    setElementData(player, "elementCheckpointBus", marker)

 

"ERROR: Bad argument @ 'destroyElement' [Expected element at argument 1, got bolean]"

 

though an error, but the marker destroy normally

 

thx developer mta for wonderful scripting lang and very wonderful api

Link to comment
33 minutes ago, s2sk said:

thx developer mta for wonderful scripting lang and very wonderful api

If you think this is a problem of this scripting language or the API, I honestly don't know how you want to have any success in writing code. Literally any weak-typed language will give you these runtime errors when you try to add an integer to a boolean, or when you attempt to destroyElement a false/nil.

The error message LITERALLY tells you the problems.

Quote

"ERROR: attempt to perform arithmetic on a boolean value 'countCheckpoint '"

You're attempting to perform arithmetic (addition, subtraction, etc) on a BOOLEAN, most likely a false value (that's what getElementData returns when there is not data set)

local countCheckpoint = getElementData(player, "countCheckpoitBusRoad") -- you could also add "or 0" afterwards to make it default to a 0 when it's false/nil
if (countCheckpoint) then
  countCheckpoint = countCheckpoint + 1 -- attempt arithmetic ONLY WHEN YOU KNOW IT'S NOT false/nil to avoid errors
end
Quote

"ERROR: Bad argument @ 'destroyElement' [Expected element at argument 1, got bolean]"

You're attempting to use destroyElement to destroy a BOOLEAN, most likely a false value (that's what getElementData returns when there is no data set). The function name even tells you that the function's purpose is to destroy an ELEMENT, not a BOOLEAN.

local elem = getElementData(player, "elementCheckpointBus")
if (isElement(elem)) then
  destroyElement(elem) -- attempt to destroy it ONLY IF YOU KNOW IT'S AN ELEMENT to avoid errors
end

 

Edited by MrTasty
Link to comment
15 minutes ago, MrTasty said:

If you think this is a problem of this scripting language or the API, I honestly don't know how you want to have any success in writing code. Literally any weak-typed language will give you these runtime errors when you try to add an integer to a boolean, or when you attempt to destroyElement a false/nil.

The error message LITERALLY tells you the problems.

You're attempting to perform arithmetic (addition, subtraction, etc) on a BOOLEAN, most likely a false value (that's what getElementData returns when there is not data set)


local countCheckpoint = getElementData(player, "countCheckpoitBusRoad") -- you could also add "or 0" afterwards to make it default to a 0 when it's false/nil
if (countCheckpoint) then
  countCheckpoint = countCheckpoint + 1 -- attempt arithmetic ONLY WHEN YOU KNOW IT'S NOT false/nil to avoid errors
end

You're attempting to use destroyElement to destroy a BOOLEAN, most likely a false value (that's what getElementData returns when there is no data set). The function name even tells you that the function's purpose is to destroy an ELEMENT, not a BOOLEAN.


local elem = getElementData(player, "elementCheckpointBus")
if (isElement(elem)) then
  destroyElement(elem) -- attempt to destroy it ONLY IF YOU KNOW IT'S AN ELEMENT to avoid errors
end

 

can you tell me, ragul, how does this help if everything goes perfectly without her?

Edited by s2sk
Link to comment
Just now, s2sk said:

everything goes perfectly without her?

But you just said you're getting errors. That means it doesn't work "perfectly".

Quote

 MY SYSTEM-BUS WORK, BUT IN CONSOLE MORE ERROR 

When an API error returns an error, it does not stop the execution of the code, it simply fails. That call fails, it does nothing, and the code continues on. This does not mean it works perfectly. It continues - not perfectly, but at least it works.

Link to comment
3 minutes ago, MrTasty said:

But you just said you're getting errors. That means it doesn't work "perfectly".

When an API error returns an error, it does not stop the execution of the code, it simply fails. That call fails, it does nothing, and the code continues on. This does not mean it works perfectly. It continues - not perfectly, but at least it works.

That means what developer mta stupid, created MP with ideal sync and anticheat and make f*k sh*t under name LUA

Link to comment

I'd like to point out that MTA didn't invent Lua. Lua is its own independent language used for a plethora of applications, including MTA. It seems to be that the only thing you're complaining about is that the MTA API is outputting errors into the console to let you know that you write bad code, and you're getting mad at MTA and Lua for it. It's your own fault.

I can imagine you dereferencing a null pointer and complaining that you get a memory access violation but you willfully refuse to check whether the pointer is null before attempt to dereference because "it's not my fault the language is bad wah wah," or complaining that math is broken because you can't divide by 0.

If you don't like it, you should just go back to PAWN and the only software that uses it - SAMP. 

  • Like 1
  • Haha 1
Link to comment
  • Moderators
3 hours ago, s2sk said:

That means what developer mta stupid, created MP with ideal sync and anticheat and make f*k sh*t under name LUA

There are a lot of languages that crash if you make mistakes like that. But no, lua gives you and error and keeps working even though the execution of the function stops.

It is a very forgiving language, you just have to learn the meaning behind the errors and warnings. > Google <

 

Please be patient. It takes at least a year or two to learn everything before you start making less mistakes in your code.

 

Edited by IIYAMA
Link to comment
  • 2 years later...
  • IIYAMA locked this topic
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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