What's new

tabela, prosty problem

Aragornkk

Senior User
Joined
Oct 11, 2008
Messages
705
Reaction score
44
Witajcie, tu znowu ja z moimi noobowskimi problemami :d
zrobi?em tabele
local bz = {
[1] = "TAK",
[2] = "NIE"
}
ale jak zrobi? aby 2 odnosi?a si? tak?e do 3,4,5,6,7 itd warto?ci funckji bez wypisywania ich
co? takiego aby by?o ?e:
local bz = {
[1] = "TAK",
else = "NIE"
}
 
T

Tairens

Guest
Odp: tabela, prosty problem

Po co tworzy? tablic? skoro tylko dla jednej warto?ci masz inn? warto?? , lepiej napisa? funkcj? prosz? ja Ciebie patrz:

Code:
local function getValue(value)
	if(value == 1) then
		return "tak"
	end
return "nie"
end
Jednak mo?e si? zdarzy?, ?e chcesz przes?a? ca?? tablic? jako warto?? to patrz jak to zrobi?:

Code:
local function getValue(value)
	local newValues = {[1] = {odpowiedz = "TAK", level = 1}, [2] = {odpowiedz = "NIE", level = 2}}
	if(value == 1) then
		return newValues[1]
	end
return newValues[2]
end

Wtedy poruszasz si? tak:

Code:
local arrayos = getValue(2)
print(arrayos.odpowiedz)
print(arrayos.level)

Mam nadziej?, ?e do?? jasno to wyt?umaczy?em
 

Dragonas

Advanced User
Joined
Jul 11, 2009
Messages
321
Reaction score
18
Age
31
Odp: tabela, prosty problem

A nie czasem:
Code:
local function getValue(value)
	if(value == 1) then
		return "tak"
	else
                return "nie"
        end
end
 

Aragornkk

Senior User
Joined
Oct 11, 2008
Messages
705
Reaction score
44
Odp: tabela, prosty problem

To b?dzie to samo, ok dzi?ki spr?buj? tak zrobi? jak m?wisz, najgorzsze jest to ?e w dosendtextmesenge nie mog? (w ?rodku jej) zacz?? kolejnej funkcji.

Ale to p??niej powiem czy jako? poradzi?em z tym sobie.
Drug? spraw? jest zrobienie "enter?w" w funckji doPlayerPopupFYI, bynajmniej nie chodzi mi oczywi?cie o /n.
Jak ka?dy wie jak wszystko si? zlepia w wiadomo?ci to nic nie mo?na odczyta?. Chcia?bym aby kto? mi pokaza? jak mo?na "entery" robi? w tej w?a?nie funckji.(jakby kto? nie wiedzia?, silnik odczytuje enter za "symbol")
Mniej wi?cej tak chc? aby to wygl?da?o:
doPlayerPopupFYI(cid, "Witaj ".. funckja .."/n
czego chcesz ".. funckja .."/n
dzie? dobry ".. funckja .."/n
/n
")



Sorki ?e tak bez przerwy pisz? ale dopiero teraz zaczynam optymalizowa? skrypty.
 
Last edited by a moderator:

Aragornkk

Senior User
Joined
Oct 11, 2008
Messages
705
Reaction score
44
Odp: tabela, prosty problem

Od?wie?am, teraz g??wnie zale?y mi na mo?liwo?ci dodaniu enter?w w skrypcie, w czasie dodawania wiadomo?ci doPlayerPopupFYI
 

Aragornkk

Senior User
Joined
Oct 11, 2008
Messages
705
Reaction score
44
Odp: tabela, prosty problem

Od?wie?am.
Refresh.
Verfris.
刷新。
(znaki)
 

Stelma

Active User
Joined
Jan 6, 2009
Messages
114
Reaction score
19
Odp: tabela, prosty problem

1. Zgadzam si? z Tairens'em (odmienia si? to ??, Je?eli nie to nie chcia?em urazi? akurat dzi? :p). A dlaczego nie mo?esz zacz?? kolejnej funkcji ?

Czym jest przecie? :
Code:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Text")

Jak funkcj? z trzema parametrami / argumentami (pisz? bo kilka wersji czyta?em / s?ysza?em ju?).

Wi?c dlaczego niby nie mo?esz zrobi? tak :
Code:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, [color=brown]getValue(1)[/color])

2. Przejrzyj sobie ten kod, jest to kod od spellbook'a znajdziesz go te? w ka?dym tfs'ie mam nadzieje ?e to rozwi??e tw?j problem:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local t = {}
	for i = 0, getPlayerInstantSpellCount(cid) - 1 do
		local spell = getPlayerInstantSpellInfo(cid, i)
		if(spell.level ~= 0) then
			if(spell.manapercent > 0) then
				spell.mana = spell.manapercent .. "%"
			end

			table.insert(t, spell)
		end
	end

	table.sort(t, function(a, b) return a.level < b.level end)
	local text, prevLevel = "", -1
	for i, spell in ipairs(t) do
		local line = ""
		if(prevLevel ~= spell.level) then
			if(i ~= 1) then
				line = "\n"
			end

			line = line .. "Spells for Level " .. spell.level .. "\n"
			prevLevel = spell.level
		end

		text = text .. line .. "  " .. spell.words .. " - " .. spell.name .. " : " .. spell.mana .. "\n"
	end

	doShowTextDialog(cid, item.itemid, text)
	return true
end
 
Top