Crash from custom spells
Crash from custom spells
I have custom spells in my mod that crash the client when added to the character as a trait. Wondering if anyone has a solution to this.
I only defineSpell{} to create custom spells. I tried addTrait and not adding the trait and the game adds it either way but crashes because of a problem with adding the trait. It does not happen to me but to others, and I recall I used to have the issue before. I tried defineTrait{} so that the game knew about the spell but it never gets used.
Thanks for any suggestions.
I only defineSpell{} to create custom spells. I tried addTrait and not adding the trait and the game adds it either way but crashes because of a problem with adding the trait. It does not happen to me but to others, and I recall I used to have the issue before. I tried defineTrait{} so that the game knew about the spell but it never gets used.
Thanks for any suggestions.
- AndakRainor
- Posts: 674
- Joined: Thu Nov 20, 2014 5:18 pm
Re: Crash from custom spells
Are your spells correctly defined during the initialization of your mod ? (you can't use the define... functions after that)
Do you have both the spellIcon for the runes panel and icon for the traits panel for those spells ?
What is the error you get, does it tell you that the trait with the name of your spell does not exist ?
Can you show the code you use to define one of those spells ?
Do you have both the spellIcon for the runes panel and icon for the traits panel for those spells ?
What is the error you get, does it tell you that the trait with the name of your spell does not exist ?
Can you show the code you use to define one of those spells ?
Re: Crash from custom spells
This is the error...
mod_assets/scripts/init.lua:196: attempt to index a nil value
stack traceback:
[C]: in function 'error'
[string "ScriptInterface.lua"]: in function 'addTrait'
mod_assets/scripts/init.lua:196: in function <mod_assets/scripts/init.lua:46>
[string "Component.lua"]: in function 'callHook'
[string "Champion.lua"]: in function 'castSpell'
[string "RunePanel.lua"]: in function 'updatePanel'
[string "AttackPanel.lua"]: in function 'update'
[string "AttackPanel.lua"]: in function 'update'
[string "Gui.lua"]: in function 'draw'
[string "GameMode.lua"]: in function 'update'
[string "Grimrock.lua"]: in function 'display'
[string "Grimrock.lua"]: in main chunk
Here is the only thing that I do currently to implement a spell. I feel like maybe I'm missing a step and that's what is causing the issue on addTrait for some.
mod_assets/scripts/init.lua:196: attempt to index a nil value
stack traceback:
[C]: in function 'error'
[string "ScriptInterface.lua"]: in function 'addTrait'
mod_assets/scripts/init.lua:196: in function <mod_assets/scripts/init.lua:46>
[string "Component.lua"]: in function 'callHook'
[string "Champion.lua"]: in function 'castSpell'
[string "RunePanel.lua"]: in function 'updatePanel'
[string "AttackPanel.lua"]: in function 'update'
[string "AttackPanel.lua"]: in function 'update'
[string "Gui.lua"]: in function 'draw'
[string "GameMode.lua"]: in function 'update'
[string "Grimrock.lua"]: in function 'display'
[string "Grimrock.lua"]: in main chunk
Here is the only thing that I do currently to implement a spell. I feel like maybe I'm missing a step and that's what is causing the issue on addTrait for some.
Code: Select all
defineSpell{
name = "burstflame",
uiName = "Burst of Flame",
gesture = 1,
manaCost = 10,
skill = "fire_magic",
requirements = { "fire_magic", 1 },
icon = 60,
spellIcon = 1,
description = "Fire based Direct Damage.",
onCast = function(champion)
local x = party.x
local y = party.y
if party.facing == 0 then
y = y - 1
elseif party.facing == 1 then
x = x + 1
elseif party.facing == 2 then
y = y + 1
elseif party.facing == 3 then
x = x - 1
end
local s = spawn("burstflame",party.level,x,y,party.facing,party.elevation)
m = 10 + champion:getCurrentStat("willpower") * 2 * (champion:getSkillLevel("fire_magic") * .4)
s.tiledamager:setAttackPower(m)
end,
}- AndakRainor
- Posts: 674
- Joined: Thu Nov 20, 2014 5:18 pm
Re: Crash from custom spells
The spell seems correctly defined, what is this function in init.lua (line 196; 48) that raised the error ? Is it the line where you call champion:addTrait("burstflame") ?
You don't need to add the spells traits yourself, the game engine does it for you when you cast a new spell, so you should may be remove that function, it is useless unless you have some other goal in mind with it.
You don't need to add the spells traits yourself, the game engine does it for you when you cast a new spell, so you should may be remove that function, it is useless unless you have some other goal in mind with it.
Re: Crash from custom spells
It is pointing to an if statement of mine. 196 is "if slot0 >= 0 then"
I commented the add trait part out and it still crashed.
I commented the add trait part out and it still crashed.
Code: Select all
local slot0 = -1
if champion:getItem(i) ~= nil and champion:getItem(i).go.name == itemName then
--hudPrint(champion:getName() .. " learned a new spell!" )
--champion:addTrait(spellName)
champion:removeItemFromSlot(i)
if slot0 >= 0 then
if champion:getItem(slot0):getStackSize() > 1 then --only remove 1
champion:getItem(slot0):setStackSize(champion:getItem(slot0):getStackSize()-1)
else ---removeslot
champion:removeItemFromSlot(slot0)
end
end
end- AndakRainor
- Posts: 674
- Joined: Thu Nov 20, 2014 5:18 pm
Re: Crash from custom spells
Well that's odd because the error says it occurred in the addTrait function, and in your code this line is commented and I don't see another call to it. Could it be that you didn't save / refresh the editor correctly ?
edit: post 11111 in this forum
edit: post 11111 in this forum
Re: Crash from custom spells
I upload a new copy because that should have been the reason and maybe something went wrong during the upload of the new copy. Could you test it for me? It didn't happen to me before or after so I can't test it myself.
http://steamcommunity.com/sharedfiles/f ... =616038736
Edit!
http://steamcommunity.com/sharedfiles/f ... =616038736
Edit!
- AndakRainor
- Posts: 674
- Joined: Thu Nov 20, 2014 5:18 pm
Re: Crash from custom spells
I just tested your dat file and it worked correctly. The magic missile spell consumed the spell scroll as expected.
Re: Crash from custom spells
Great. I hope it is fixed for everyone, thanks.