Forum

> > CS2D > Scripts > Change value in table
Forums overviewCS2D overview Scripts overviewLog in to reply

English Change value in table

5 replies
To the start Previous 1 Next To the start

old Change value in table

-DIE Wolf-
User Off Offline

Quote
First, test this one : ( Renember to make function Array)

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]

old Re: Change value in table

MikuAuahDark
User Off Offline

Quote
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.
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]}

old Re: Change value in table

EngiN33R
Moderator Off Offline

Quote
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.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview