Crash from custom spells

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
bumbaclad
Posts: 12
Joined: Thu Feb 04, 2016 11:59 pm

Crash from custom spells

Post by bumbaclad »

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.
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Crash from custom spells

Post by AndakRainor »

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 ?
bumbaclad
Posts: 12
Joined: Thu Feb 04, 2016 11:59 pm

Re: Crash from custom spells

Post by bumbaclad »

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.

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,
}
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Crash from custom spells

Post by AndakRainor »

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.
bumbaclad
Posts: 12
Joined: Thu Feb 04, 2016 11:59 pm

Re: Crash from custom spells

Post by bumbaclad »

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.

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
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Crash from custom spells

Post by AndakRainor »

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 :)
bumbaclad
Posts: 12
Joined: Thu Feb 04, 2016 11:59 pm

Re: Crash from custom spells

Post by bumbaclad »

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!
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Crash from custom spells

Post by AndakRainor »

I just tested your dat file and it worked correctly. The magic missile spell consumed the spell scroll as expected.
bumbaclad
Posts: 12
Joined: Thu Feb 04, 2016 11:59 pm

Re: Crash from custom spells

Post by bumbaclad »

Great. I hope it is fixed for everyone, thanks.
Post Reply