Forum

> > CS2D > Scripts > Arrays in MedievalMod gone wrong.
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Arrays in MedievalMod gone wrong.

9 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Arrays in MedievalMod gone wrong.

Alistaire
User Off Offline

Zitieren
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function MultiArray(iS,bIM,cIM,iMS,iMS2)
	DA = {};
	for i=0,iS do
		if (bIM) then DA[i] = {};
			for i2=0,iMS do
				if (cIM) then DA[i][i2] = {};
					for i3=0,iMS2 do DA[i][i2][i3] = 0;
					end
				else DA[i][i2] = 0;
				end
			end
		else DA[i] = 0;
		end
	end
	return DA;
end

class_cnt = MultiArray(32,true,true,7,9999)
MM_class = MultiArray(32,false,false,0,0)
class_cnt[id][MM_class[id]]['frags'] = 0

function MM_serveraction(id,action)
	if action==1 then
		MM_classmenu(id)
	end
end
function MM_classmenu(id)
	menu(id,"Medieval Mod classes@b,Hobilar|Horse,Bandit|Shield,Bowman|Bow,Ballista|Ballista,Apprentice|Heal,Thief|Stealth,Madman|Rage,Random")
end

function MM_menu(id,menu,sel)
	if (menu=="Medieval Mod classes") then
		if(sel>=1)and(sel<=7)then
			if sel~=MM_class[id] then
				MM_class[id]=sel
				if(player(id,"health")>0)then
					parse("killplayer "..id)
				end
			elseif sel==MM_class[id] then
				msg2(id,"©255000000[Script]: You already are this class!")
			end
		end
	end
end

function MM_spawn(id)
	if(MM_class[id]<1)or(MM_class[id]>7)then
		MM_class[id]=math.random(1,7)
	end
	if(MM_class[id]==1)then
		if(class_cnt[id][MM_class[id]]['frags']<10)then
		end
	end
end

That's a lot of crappy script yeah; but look at this.

Lua Error #1 hat geschrieben
[12:43:46] LUA ERROR: sys/lua/medieval mod.lua:103: attempt to compare nil with number

1
if(class_cnt[id][MM_class[id]]['frags']<10)then

Lua Error #2 hat geschrieben
[12:44:33] LUA ERROR: sys/lua/medieval mod.lua:47: attempt to index field '?' (a nil value)

1
class_cnt[id][MM_class[id]]['frags'] = 0

I won't post more of the code since it's about 800 lines. With ugly tabbing. Should fix that soon..

----

Anyone knows how to make this ['frags'] thing work? Or is the MultiArray function wrong? I honestly don't know.

alt Re: Arrays in MedievalMod gone wrong.

EngiN33R
Moderator Off Offline

Zitieren
Do what Kel says - you need to make MM_class just a table and make the class_cnt declaration line this:

1
2
3
for i=1,32 do
	class_cnt[id][MM_class[id]]['frags'] = 0
end

@user Kel9290: there is no such thing as 'standard initArray' - the infamous initArray function is custom.

alt Re: Arrays in MedievalMod gone wrong.

MikuAuahDark
User Off Offline

Zitieren
1
.
add "."(without quotes) before "['frags']"
1
class_cnt[id][MM_class[id]].['frags'] = 0
or
1
class_cnt[id].[MM_class[id]].['frags'] = 0
or
1
class_cnt[id].[MM_class[id]]['frags'] = 0
also add user EngiN33R code too(2 post above me)
if that is not solve your problem, yea something wrong at multiarray

alt Re: Arrays in MedievalMod gone wrong.

Alistaire
User Off Offline

Zitieren
Spoiler >


----

I've added that line but the Error #2 keeps returning nonetheless. Should I remove the 'MM_class[id]' and place 'MM_class' since [id] already knows what player it is? Idk..
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht