• Make text disappear and appear after some time
    7 replies, posted
Hi, i'm using this code to display random text for players. The question is, is it possible to make text disappear after 10 seconds and then appear with random text? [CODE]local hints = { -- table of options "Random text 1", "Random text 2" } local current = math.random(#hints) -- index of currently displayed text from the table local function newRandom() -- function to change current text to some other random entry local old = current -- prevent same items from being chosen twice in a row while current == old do current = math.random(#hints) end end timer.Create("My Hints", 50, 0, newRandom) local function drawText() -- function to actually draw our text draw.DrawText(hints[current]) end hook.Add("HUDPaint", "My Hints", drawText)[/CODE]
Don't use while, it will crash the game, add your hook when you need to draw it and use hook.Remove to remove it from drawing
[QUOTE=gonzalolog;52908106]Don't use while, it will crash the game[/QUOTE] no it won't
[QUOTE=gonzalolog;52908106]Don't use while, it will crash the game, add your hook when you need to draw it and use hook.Remove to remove it from drawing[/QUOTE] Going to need some clarification on this.
[QUOTE=gonzalolog;52908106]Don't use while, it will crash the game, add your hook when you need to draw it and use hook.Remove to remove it from drawing[/QUOTE] It'll only crash if the randomly chosen hint is the same as the last hint over a large number of iterations. As long as the size of the hint array is more than 1, it should be near impossible to crash the game.
There is no need to create two threads for the same problem? You got an answer in your last thread?? [quote] Yes, this should help you. [url]https://www.lua.org/pil/4.2.html[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/CurTime]CurTime[/url] [/quote]
No, it would have to be the same an infinite number of times, which is pretty much impossible. You might drop like 3 fps when it's called but that's about it.
Sorry, you need to Log In to post a reply to this thread.