Tokio

[HELP] Why not working setTimer function?

Recommended Posts

i have this code:

setTimer(function()
	local arfolyam = math.random(200,5130)
	outputChatBox("Jelenlegi árfolyam: "..arfolyam)
end, 500, 0)

        GUIEditor.window[1] = guiCreateWindow(0.35, 0.31, 0.31, 0.28, "Aranykereskedés", true)
        guiWindowSetSizable(GUIEditor.window[1], false)
        GUIEditor.label[1] = guiCreateLabel(0.02, 0.59, 0.95, 0.14, "Az arany jelenlegi árfolyama: "..arfolyam, true, GUIEditor.window[1])

but i get this error in debugscript 3:

attempt to concatenate global 'arfolyam' ( a nil value) 

 

what wrong? how to fix this?

Share this post


Link to post
9 hours ago, Zorgman said:

Make arfolyam global

How? Because i want change the 'arfolyam' every 500 ms

Share this post


Link to post
3 minutes ago, Zorgman said:

Delete 'local'

i deleted, but same problem :S i got error :S 

Share this post


Link to post
18 hours ago, 50cent said:
  1. local arfolyam
  2. setTimer(function()
  3. arfolyam = math.random(200,5130)
  4. outputChatBox("Jelenlegi árfolyam: "..arfolyam)
  5. end, 500, 0)
  6.  
  7. GUIEditor.window[1] = guiCreateWindow(0.35, 0.31, 0.31, 0.28, "Aranykereskedés", true)
  8. guiWindowSetSizable(GUIEditor.window[1], false)
  9. GUIEditor.label[1] = guiCreateLabel(0.02, 0.59, 0.95, 0.14, "Az arany jelenlegi árfolyama: "..arfolyam, true, GUIEditor.window[1])

Try now

Share this post


Link to post
4 minutes ago, Zorgman said:

Try now

attempt to concatenate local arfolyam (a nil value) O.o

Share this post


Link to post
local arfolyam = math.random(200,5130)
setTimer(function()
arfolyam = math.random(200,5130)
outputChatBox("Jelenlegi árfolyam: "..arfolyam)
end, 500, 0)
 
GUIEditor.window[1] = guiCreateWindow(0.35, 0.31, 0.31, 0.28, "Aranykereskedés", true)
guiWindowSetSizable(GUIEditor.window[1], false)
GUIEditor.label[1] = guiCreateLabel(0.02, 0.59, 0.95, 0.14, "Az arany jelenlegi árfolyama: "..arfolyam, true, GUIEditor.window[1])

P.S.: I'm Hungarian too! ;)

Share this post


Link to post

Yeah. I think my code would have worked too after spitting errors for the first half second :)

Share this post


Link to post
58 minutes ago, MakroBox said:

local arfolyam = math.random(200,5130)
setTimer(function()
arfolyam = math.random(200,5130)
outputChatBox("Jelenlegi árfolyam: "..arfolyam)
end, 500, 0)
 
GUIEditor.window[1] = guiCreateWindow(0.35, 0.31, 0.31, 0.28, "Aranykereskedés", true)
guiWindowSetSizable(GUIEditor.window[1], false)
GUIEditor.label[1] = guiCreateLabel(0.02, 0.59, 0.95, 0.14, "Az arany jelenlegi árfolyama: "..arfolyam, true, GUIEditor.window[1])

P.S.: I'm Hungarian too! ;)

With this code, the label does not update the 'arfolyam' :S 

Share this post


Link to post
local arfolyam = math.random(200,5130)
setTimer(function()
arfolyam = math.random(200,5130)
	outputChatBox("Jelenlegi árfolyam: "..arfolyam)
	guiSetText(GUIEditor.label[1], "Az arany jelenlegi árfolyama: " .. arfolyam)
end, 500, 0)
 
GUIEditor.window[1] = guiCreateWindow(0.35, 0.31, 0.31, 0.28, "Aranykereskedés", true)
guiWindowSetSizable(GUIEditor.window[1], false)
GUIEditor.label[1] = guiCreateLabel(0.02, 0.59, 0.95, 0.14, "Az arany jelenlegi árfolyama: "..arfolyam, true, GUIEditor.window[1])

 

Edited by NeXuS™
  • Thanks 1

Share this post


Link to post
26 minutes ago, NeXuS™ said:

local arfolyam = math.random(200,5130)
setTimer(function()
arfolyam = math.random(200,5130)
	outputChatBox("Jelenlegi árfolyam: "..arfolyam)
	guiSetText(GUIEditor.label[1], "Az arany jelenlegi árfolyama: " .. arfolyam)
end, 500, 0)
 
GUIEditor.window[1] = guiCreateWindow(0.35, 0.31, 0.31, 0.28, "Aranykereskedés", true)
guiWindowSetSizable(GUIEditor.window[1], false)
GUIEditor.label[1] = guiCreateLabel(0.02, 0.59, 0.95, 0.14, "Az arany jelenlegi árfolyama: "..arfolyam, true, GUIEditor.window[1])

 

thanks:DD 

and how can i add when a player click on the button, then take the 'arfolyam' amount from player, in server side?

Share this post


Link to post
7 minutes ago, NeXuS™ said:

Using the onClientGUIClick event, some custom events, and takeMoney function.

this why not working?

client:

function arr() 
	triggerServerEvent ("ar", root, getLocalPlayer()) 
end 
addEventHandler ( "onClientGUIClick", GUIEditor.button[1], arr, false ) 

server:

addEvent( "ar", true ) 
addEventHandler( "ar", root, 
	function (thePlayer) 
	local arfolyam
	if getPlayerMoney(thePlayer) >= arfolyam then
	takePlayerMoney ( thePlayer, arfolyam )
else
	outputChatBox("Nincs elég pénzed a vásárláshoz.", thePlayer, 255, 0, 0, false)
	end
end
) 

 

Share this post


Link to post

Any errors?

Share this post


Link to post
Just now, NeXuS™ said:

Any errors?

server:5: attempt to compare nil with number

Share this post


Link to post

"arfolyam" doesnt exist on serverside, you have to send it to the server-side through the triggerServerEvent.

Share this post


Link to post

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.