English Change value in table

5 replies
Goto Page
To the start Previous 1 Next To the start
14.07.14 01:34:29 pm
Up
-DIE Wolf-
User
Offline Off
First, test this one : ( Renember to make function Array)

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Wood=Array(32,0)
Cash=Array(32,0)

addhook("serveraction","s_act")
function s_act(id,button)
     if button == 1 then
          menu(id,"Get Wood","Get Cash")
     end
end

addhook('menu','menu')
function menu(id,tile,button)
     if tile=="Get Wood" then
     test={Wood[id],Cash[id]}
          if button~= 0 then
               test[button]=test[button]+20
          end
     end
end


test[button] is equal to Wood[id]
But Wood[id] didn't change .Help

I need Wood[id] to increased by 20
Same with Cash[id]
IMG:https://www.gametracker.com/images/game_icons64/csgo.png
14.07.14 02:30:15 pm
Up
MikuAuahDark
User
Offline Off
test[button] is equal to Wood[id] but it passes the value directly, not the value reference.

You need to add it by 20 by each statement.
Code:
1
2
Wood[id]=Wood[id]+20     -- for wood
Cash[id]=Cash[id]+20     -- for cash


So you don't need test={Wood[id],Cash[id]}
Hello? Are you there, Tae Hanazono?
14.07.14 02:46:22 pm
Up
AlcatrazZ
BANNED
Offline Off
Code:
Wood[id] = test[button] + 20
Ban Reason: Multiple Accounts
15.07.14 08:06:50 am
Up
-DIE Wolf-
User
Offline Off
I'm trying to make cool way that only need 1 button. :v
IMG:https://www.gametracker.com/images/game_icons64/csgo.png
15.07.14 08:42:43 am
Up
EngiN33R
Moderator
Offline Off
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Wood=Array(32,0)
Cash=Array(32,0)

addhook("serveraction", "s_act")
function s_act(id, button)
     if (button == 1) then
          menu(id,"Test menu,Get Wood,Get Cash")
     end
end

addhook('menu', 'menu')
function menu(id, tile, button)
     if (tile=="Get Wood") then
          local reftbl = {Wood, Cash}
          if (button ~= 0) then
               reftbl[button][id] = reftbl[button][id] + 20
          end
     end
end


Since you're dying to make it use a reference table, here's a way to do it. Also, your menu was wrong.
I code, therefore I exist. | Visit my blog for Lua tips and other interesting info
16.07.14 04:36:02 am
Up
-DIE Wolf-
User
Offline Off
Thank you so much !
IMG:https://www.gametracker.com/images/game_icons64/csgo.png
To the start Previous 1 Next To the start