Вылет при нажатии кнопки "Начать сражение за.."

I_GRIN_I

Друзья CG
15 Мар 2016
1,335
105
От чего может быть такой вылет? Ошибок в консоли нет вообще. Просто нажимаю на кнопку и вылет... Менять пытался уже все что угодно, но ничего.
 
От чего может быть такой вылет? Ошибок в консоли нет вообще. Просто нажимаю на кнопку и вылет... Менять пытался уже все что угодно, но ничего.
От чего угодно.
 
Последнее редактирование модератором:
Код:
local playerID = player:GetPlayerID()
playerID.recources = playerID.recources or {}

Что не так? Где ошибка?

Код:
[  Developer      ]: ...s\surviveinthetaiga\scripts\vscripts\addon_game_mode.lua:65: attempt to index local 'playerID' (a number value)
[  Developer      ]: stack traceback:
[  Developer      ]: 	...s\surviveinthetaiga\scripts\vscripts\addon_game_mode.lua:65: in function <...s\surviveinthetaiga\scripts\vscripts\addon_game_mode.lua:54>
[ W VScript       ]: Script Runtime Error: ...s\surviveinthetaiga\scripts\vscripts\addon_game_mode.lua:65: attempt to index local 'playerID' (a number value)
[ W VScript       ]: stack traceback:
[ W VScript       ]: 	...s\surviveinthetaiga\scripts\vscripts\addon_game_mode.lua:65: in function <...s\surviveinthetaiga\scripts\vscripts\addon_game_mode.lua:54>
 
Последнее редактирование модератором:
Ты скидываешь не весь код...

Что за метод .recources у целочисленной переменной?
 
Илья, это не метод, я хочу создать переменную в которую ресурсы игрока будут записываться по его ид. И у каждого будет своя переменная
 
GetPlayerID() - метод, что возвращает целочисленную переменную (integer).

integer - это не какой-то там класс, у которого можно создавать произвольные методы.
 
Илья, а у чего тогда создать метод можно, что бы не менялось после перезахода в игру?
 
Код:
PlayerResource.myCustomResource = PlayerResource.myCustomResource or {}
PlayerResource.myCustomResource[playerID] = 42
 
Ладно, а что не так здесь тогда?
Код:
if changes == nil then
 	changes = class({})
end

function changes:changewood(playerid,changewood)
	if playerid == 0 then
		_G.onerecources["wood"] 	= (_G.onerecources["wood"] + changewood) or 0
		print(onerecources["wood"])
	elseif playerid == 1 then
		_G.tworecources["wood"] 	= (_G.tworecources["wood"] + changewood) or 0
		print(tworecources["wood"])
	elseif playerid == 2 then
		_G.treerecources["wood"] 	= (_G.treerecources["wood"] + changewood) or 0
		print(treerecources["wood"])
	elseif playerid == 3 then
		_G.fourrecources["wood"] 	= (_G.fourrecources["wood"] + changewood) or 0
		print(fourrecources["wood"])
	elseif playerid == 4 then
		_G.fiverecources["wood"] 	= (_G.fiverecources["wood"] + changewood) or 0
		print(fiverecources["wood"])
	elseif playerid == 5 then
		_G.sixrecources["wood"] 	= (_G.sixrecources["wood"] + changewood) or 0
		print(sixrecources["wood"])
	elseif playerid == 6 then
		_G.sevenrecources["wood"] 	= (_G.sevenrecources["wood"] + changewood) or 0
		print(sevenrecources["wood"])
	elseif playerid == 7 then
		_G.eithrecources["wood"] 	= (_G.eithrecources["wood"] + changewood) or 0
		print(eithrecources["wood"])
	elseif playerid == 8 then
		_G.ninerecources["wood"] 	= (_G.ninerecources["wood"] + changewood) or 0
		print(ninerecources["wood"])
	elseif playerid == 9 then
		_G.tenrecources["wood"] 	= (_G.tenrecources["wood"] + changewood) or 0
		print(tenrecources["wood"])
	end
end

function changes:changestone(playerid,changestone)
	if playerid == 0 then
		_G.onerecources["stones"] 		= (_G.onerecources["stones"] + changestone) or 0
		print(onerecources["stones"])
	elseif playerid == 1 then
		_G.tworecources["stones"] 		= (_G.tworecources["stones"] + changestone) or 0
		print(tworecources["stones"])
	elseif playerid == 2 then
		_G.treerecources["stones"] 		= (_G.treerecources["stones"] + changestone) or 0
		print(treerecources["stones"])
	elseif playerid == 3 then
		_G.fourrecources["stones"] 		= (_G.fourrecources["stones"] + changestone) or 0
		print(fourrecources["stones"])
	elseif playerid == 4 then
		_G.fiverecources["stones"] 		= (_G.fiverecources["stones"] + changestone) or 0
		print(fiverecources["stones"])
	elseif playerid == 5 then
		_G.sixrecources["stones"] 		= (_G.sixrecources["stones"] + changestone) or 0
		print(sixrecources["stones"])
	elseif playerid == 6 then
		_G.sevenrecources["stones"] 	= (_G.sevenrecources["stones"] + changestone) or 0
		print(sevenrecources["stones"])
	elseif playerid == 7 then
		_G.eithrecources["stones"] 		= (_G.eithrecources["stones"] + changestone) or 0
		print(eithrecources["stones"])
	elseif playerid == 8 then
		_G.ninerecources["stones"] 		= (_G.ninerecources["stones"] + changestone) or 0
		print(ninerecources["stones"])
	elseif playerid == 9 then
		_G.tenrecources["stones"] 		= (_G.tenrecources["stones"] + changestone) or 0
		print(tenrecources["stones"])
	end
end

Код:
[  Developer      ]: scripts/vscripts/changes.lua:41: attempt to perform arithmetic on field 'stones' (a nil value)
[  Developer      ]: stack traceback:
[  Developer      ]: 	scripts/vscripts/changes.lua:41: in function 'changestone'
[  Developer      ]: 	...rviveinthetaiga\scripts\vscripts\abilities\gathering.lua:21: in function <...rviveinthetaiga\scripts\vscripts\abilities\gathering.lua:1>
[ W VScript       ]: Script Runtime Error: scripts/vscripts/changes.lua:41: attempt to perform arithmetic on field 'stones' (a nil value)
[ W VScript       ]: stack traceback:
[ W VScript       ]: 	scripts/vscripts/changes.lua:41: in function 'changestone'
[ W VScript       ]: 	...rviveinthetaiga\scripts\vscripts\abilities\gathering.lua:21: in function <...rviveinthetaiga\scripts\vscripts\abilities\gathering.lua:1>

Вот откуда вызывается функция:
Код:
function Gather(keys)
	local caster = keys.caster
	local ability = keys.ability
  	local point = caster:GetCursorPosition()
  	local findents = GridNav:GetAllTreesAroundPoint(point, 150, false)
  	local playerid = caster:GetPlayerOwnerID()
  	local woodmin = ability:GetSpecialValueFor("woodmin")
  	local woodmax = ability:GetSpecialValueFor("woodmax")
  	local stonemin = ability:GetSpecialValueFor("stonemin")
  	local stonemax = ability:GetSpecialValueFor("stonemax")
  	local multiplier = ability:GetSpecialValueFor("treemultiplier")
  	local wood = math.random(woodmin,woodmax)
  	local stone = math.random(stonemin,stonemax)
  	if #findents >= 1 then
  		local trees = tonumber(#findents)
  		local woodtotranslate = wood * (1 + trees * multiplier)
  		print(woodtotranslate)
  		changes:changewood(playerid,tonumber(woodtotranslate))
  	else
  		print(stone)
  		changes:changestone(playerid,tonumber(stone))
  	end
end

Переменные объявлял:
Код:
_G.onerecources 	= _G.onerecources 	or {}
_G.tworecources 	= _G.tworecources 	or {}
_G.treerecources 	= _G.treerecources 	or {}
_G.fourrecources 	= _G.fourrecources 	or {}
_G.fiverecources 	= _G.fiverecources 	or {}
_G.sixrecources 	= _G.sixrecources 	or {}
_G.sevenrecources 	= _G.sevenrecources 	or {}
_G.eithrecources 	= _G.eithrecources 	or {}
_G.ninerecources 	= _G.ninerecources 	or {}
_G.tenrecources 	= _G.tenrecources 	or {}
 
Последнее редактирование модератором:
Чем тебе 2 строчки сверху не угодили? И почему ты решил использовать вместо них эту ужасную конструкцию?
 
Ты точно индус.
Вот ошибка:
Код:
_G.onerecources["wood"] 	= (_G.onerecources["wood"] + changewood) or 0
Меняй на
Код:
_G.onerecources["wood"] 	= (_G.onerecources["wood"] or 0) + changewood
Иначе выходит (nil + changewood) or 0




И вообще убери нахрен всю эту систему и сделай так:
Код:
local PLAYER_COUNT = 10
_G.resources = {}

for playerid = 0, PLAYER_COUNT do
	_G.resources[playerid] = {}
end

А потом уже делай в своем changewood так:
Код:
function changes:changewood(playerid,changewood)
	_G.resources[playerid]["wood"] = (_G.resources[playerid]["wood"] or 0) + changewood
	print(_G.resources[playerid]["wood"])
end
Или на крайняк так
Код:
_G.resources = {}

А потом уже делай в своем changewood так:
Код:
function changes:changewood(playerid,changewood)
	_G.resources[playerid] = _G.resources[playerid] or {}
	_G.resources[playerid]["wood"] = (_G.resources[playerid]["wood"] or 0) + changewood
	print(_G.resources[playerid]["wood"])
end
Видишь почему ты индус?
 
Последнее редактирование модератором:
CryDeS, я просто ответа не дождался, начал делать велосипеды, спасибо вам
 
[quote author=I_GRIN_I link=topic=1089.msg6233#msg6233 date=1473705431]
CryDeS, я просто ответа не дождался, начал делать велосипеды, спасибо вам
[/quote]
Тебе вон сверху злой скинул то же самое что и я.
Игнорщик
 
Реклама: