Xwaw Posted January 14, 2020 Share Posted January 14, 2020 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 Link to comment
Scripting Moderators ds1-e Posted January 14, 2020 Scripting Moderators Share Posted January 14, 2020 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? Link to comment
Moderators Patrick Posted January 14, 2020 Moderators Share Posted January 14, 2020 In line 4 don't use local, because you want to change the global g variable's value. Now, you change g only inside giveGold function's scope, what has no effect on the global g variable in the first line. 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