Sign in to follow this  
Xwaw

I have problems with my scripts

Recommended Posts

local g = 0

function giveGold()
	local g = g+1
end

addCommandHandler("giveG", giveGold)

function showGold(source)
	outputChatBox(tostring(g), 255, 255, 0)
end

addCommandHandler("showG", showGold)

I mean, I want the "showG" command to show the Player amount of gold, and the "giveG" command wants it to add the Player amount of gold. It is on the client side.

PLS HELP

Share this post


Link to post
25 minutes ago, Xwaw said:

local g = 0

function giveGold()
	local g = g+1
end

addCommandHandler("giveG", giveGold)

function showGold(source)
	outputChatBox(tostring(g), 255, 255, 0)
end

addCommandHandler("showG", showGold)

I mean, I want the "showG" command to show the Player amount of gold, and the "giveG" command wants it to add the Player amount of gold. It is on the client side.

PLS HELP

So explain what doesn't work in here?

 

Share this post


Link to post

In line 4 don't use local, because you want to change the global variable's value.

Now, you change g only inside giveGold function's scope, what has no effect on the global variable in the first line.

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.