Help me spot a mistake in a short LUA script

Hi guys, can you please spot my mistake here… today i created my first resource with idea from other script as a learning platform…

In a RunOnce client style LUA

ListBlips[k] looks ok
addBlips( ListBlips[k] ) should be ok i guess
in the function addBlips, im trying to get the last var called “showonmap” … which should be “true”
chatMessage is always showonmap = false.

Doing ListBlips[k] won’t just assign each item to the parameters. It will try to send the table as one parameter.

You need to break it down more and do ListBlips[k][0], ListBlips[k][1], ListBlips[k][2], and so on for the parameters

1 Like

well… i taught i was already doing that, lol

  1. my client.ula call the fonction BD_Blips(true)

  2. i have to admit i did not quite master what the “in pairs” mean… even after small research. k will increment by 1 to “pass” each element in my ListBlips local variable/“table”. i guess “v” does mean the variable number. no clue about the “in pairs” unfortunately. but… when i triggerevent chatmessage with ListBlips[k] … on each step its the right answer… each of my blip listed above

oh wait… i think i just found what you mean… lets go try… the values in the fonction addBlips is not good.

Also… a little bit unrelevant but you start at [0] … but i taught for k,v … the first try was a [1] …

EDIT: its working perfectly as i needed it to be… thank you very much @Briglair

If anyone is curious… here is my code https://pastebin.com/bgmsX2ay

Oh, if it works at 1, then yeah. Usually with coding and arrays and stuff it always starts at 0. Just a habit for me.

You shouldn’t need to do this:

            ListBlips[k].y = v[2]
            ListBlips[k].z = v[3]
            ListBlips[k].idtype = v[4]
            ListBlips[k].idcolor = v[5]
            ListBlips[k].size = v[6]
            ListBlips[k].text = v[7]
            ListBlips[k].showonmap = v[8]

k is the key for that table. It will never change. In fact, you could just call v[1] v[2] in the addBlips() thing itself.

I forgot exactly how it worked. I haven’t used inpairs in a little bit, but all inpairs does is return each key/value pair in a table.

you are right… now that it work as i wanted… i was wondering if it could be optimized… lets try

i also noticed my showonmap is working but if i set the blip scalesize to 1 (and not to 1.0 which work) it accidentally does the same job with way less control… another way to make the blips disappear but with shaving an extra variable off… lol

I did tried the first time to use addBlips(v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8]) … but I must had mistakes elsewhere and scrapped that way

EDIT: Failure so far

addBlips(ListBlips[k][1],ListBlips[k][2],ListBlips[k][3],ListBlips[k][4],ListBlips[k][5],ListBlips[k][6],ListBlips[k][7],ListBlips[k][8])

or

addBlips(v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8])

or

addBlips(ListBlips.v[1],ListBlips.v[2],ListBlips.v[3],ListBlips.v[4],ListBlips.v[5],ListBlips.v[6],ListBlips.v[7],ListBlips.v[8])

addBlips(v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8]) did worked…

What I have learned today 11h later… the name of my table is case sensitive… Listblips and ListBlips are a world of difference… i change my code for hours and hours … AAAARRRRRGGH GOD WHY??

well im off to bed with a working script… i earn the right!

Everything is case-sensitive. Gotta love those silly little things that get you :slight_smile: