manuelhimmler Posted November 29, 2009 Share Posted November 29, 2009 I have scriptet a text function: function GameTextForPlayer(player,text,milliseconds,r,g,b,zeile) if zeile == nil then zeile=1 end if zeile == 1 then if isTimer(gametimer[1][player]) then killTimer(gametimer[1][player]) textDestroyDisplay(gametext[1][player]) end gametext[1][player] = textCreateDisplay() textDisplayAddObserver(gametext[1][player],player) local scrx = getElementData(player,"player.sx") local scry = getElementData(player,"player.sy") local textItem = textCreateTextItem(tostring(text), 0.5, 0.2875, 0,tonumber(r), tonumber(g), tonumber(b), 255, 3, "center","center",0) textDisplayAddText(gametext[1][player],textItem) gametimer[1][player] = setTimer(textDestroyDisplay,tonumber(milliseconds),1,gametext[1][player]) else if isTimer(gametimer[zeile][player]) then killTimer(gametimer[zeile][player]) textDestroyDisplay(gametext[zeile][player]) end gametext[zeile][player] = textCreateDisplay() textDisplayAddObserver(gametext[zeile][player],player) local scrx = getElementData(player,"player.sx") local scry = getElementData(player,"player.sy") local textItem = textCreateTextItem(tostring(text), 0.5, 0.2875+((zeile-1)*0.045), 0,tonumber(r), tonumber(g), tonumber(b), 255, 3, "center","center",0) textDisplayAddText(gametext[zeile][player],textItem) gametimer[zeile][player] = setTimer(textDestroyDisplay,tonumber(milliseconds),1,gametext[zeile][player]) end end but there is often a error in this row "gametext[1][player] = textCreateDisplay()" called "table index is nil" and then the text is show the whole time, also when I destroy it. Link to comment
Gamesnert Posted November 29, 2009 Share Posted November 29, 2009 but there is often a error in this row "gametext[1][player] = textCreateDisplay()" called "table index is nil" This means that you're doing something like this: table [ nil ] In the case of "gametext[1][player]", I'd say only "player" can become nil. Are you sure you're passing the right player through to the function? Link to comment
manuelhimmler Posted November 29, 2009 Author Share Posted November 29, 2009 yes because the text works but only sometimes not oh sorry: I had forgotten a few functions to write the right player-agrument thanks but isnt there a funcction (an easy) i could use new lines (\n) and two collors or more in one sentence (string) Link to comment
robhol Posted November 29, 2009 Share Posted November 29, 2009 You can use directx drawing. https://forum.multitheftauto.com/viewtop ... 08&t=24262 by Talidan is a special "library" for text drawing, it wraps around dx functions and simplifies it abit. Link to comment
manuelhimmler Posted November 29, 2009 Author Share Posted November 29, 2009 yes, but i think there isnt a solution to use more colors in one textitem isnt it? Link to comment
50p Posted November 29, 2009 Share Posted November 29, 2009 yes, but i think there isnt a solution to use more colors in one textitem isnt it? No. Link to comment
Dark Dragon Posted November 29, 2009 Share Posted November 29, 2009 you can get a dx text's width and create a new dx text next to it Link to comment
subenji99 Posted November 30, 2009 Share Posted November 30, 2009 While the discussion moved on, I'll point out here that you are getting errors because you are forgetting that tables need to be defined before they are indexed. myTable[1][1] --will error myTable[1] --will also error myTable = {} myTable[1] -- will now return nil (index exists now, but no value has been entered yet) myTable[1][1] --will error myTable[1] = {} myTable[1] --will return TABLE: (memory address) myTable[1][1] --will return nil or you can just do: myTable = { {} } -- creates a double-array table of size myTable[1][1] so remember you need to initialize tables. Also remember however that initializing a table will wipe the table blank too, so initialize the table at a spot that only is executed once, or add: if type(myTable) ~= "table" then myTable = {} end Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now