Jump to content

Getting started with modding - Item Creation


Recommended Posts

Hello there.

Since I am trying for several weeks now (every once in a while) to get into Don't Starve modding, I am here to hope that someone can look over my previous work and tell me what I am doing wrong. I just don't get it.

I looked over several other mods like the "sampleprefab"-Mod or "logstorage"-Mod (since it also creates a new prefab) to compare the important code of them with mine but I just can't see what I am doing wrong and it's not like I have no experience in programming so I am getting a bit frustrated by such a seemingly simple matter.

I also used the BuildRenamer so the build.bin in the anim-Folder should be fine. (But I still don't get what the file anim.bin is for. I just took the anim.bin-File from the "sampleprefab"-Mod.)

Like you can see, my mod is just a example mod with no further purpose. I just want to see how the games handles the .tex-Files I created and how it behaves ingame... but when enabling the mod, it just freezes the game so there must be something wrong.

I would be soooo glad if someone could help me because I really want to get into modding :)

mymod.rar

Link to comment
Share on other sites

37 minutes ago, Mobbstar said:

Check your log.txt to find out why it freezes

Maybe the game just can't find the asset.

So, I finally have an error message for the freeze of the game.

in the log.txt, it says
 

Quote

...ps/common/dont_starve/data/scripts/mainfunctions.lua:73: Error loading file prefabs/myitem
...ont_starve/data/../mods/itemcreation_tutorial/scripts/prefabs/myitem.lua:32: 'end' expected (to close 'function' at line 9) near 'Prefab'

and this is my myitem.lua

local assets =
{    
	--Asset("ANIM", "anim/myitem.zip"),    
	--Asset("ANIM", "anim/swap_myitem.zip"),    
	Asset("ATLAS", "images/inventoryimages/myitem.xml"),    
	Asset("IMAGE", "images/inventoryimages/myitem.tex"),
}
prefabs = {}
local function fn() 
local function OnEquip(inst, owner)        
owner.AnimState:OverrideSymbol("swap_object", "swap_myitem", "swap_myitem")        owner.AnimState:Show("ARM_carry")        
owner.AnimState:Hide("ARM_normal")    
end    
local function OnUnequip(inst, owner)        
owner.AnimState:Hide("ARM_carry")        
owner.AnimState:Show("ARM_normal")    
end    local inst = CreateEntity()    
local trans = inst.entity:AddTransform()    
local anim = inst.entity:AddAnimState()    
local sound = inst.entity:AddSoundEmitter()    
MakeInventoryPhysics(inst)        
--anim:SetBank("myitem")    
--anim:SetBuild("myitem")    
--anim:PlayAnimation("idle")    
inst:AddComponent("inspectable")        
inst:AddComponent("inventoryitem")    
inst.components.inventoryitem.imagename = "myitem"    
inst.components.inventoryitem.atlasname = "images/inventoryimages/myitem.xml"        
inst:AddComponent("equippable")    
inst.components.equippable:SetOnEquip( OnEquip )    
inst.components.equippable:SetOnUnequip( OnUnequip )    
return instendreturn  Prefab("common/inventory/myitem", fn, assets, prefabs)

so there is somewhere an "end" missing? But I got this pasted from the tutorial, how can this be wrong? :o

Link to comment
Share on other sites

9 minutes ago, EKzyis said:

so there is somewhere an "end" missing? But I got this pasted from the tutorial, how can this be wrong?

You copy-pasted everything, but in a horrid manner. Here's a properly formatted version:

Spoiler

 

local assets =
{
    --Asset("ANIM", "anim/myitem.zip"),    
    --Asset("ANIM", "anim/swap_myitem.zip"),    
    Asset("ATLAS", "images/inventoryimages/myitem.xml"),    
    Asset("IMAGE", "images/inventoryimages/myitem.tex"),
}

prefabs = {}

local function OnEquip(inst, owner)        
    owner.AnimState:OverrideSymbol("swap_object", "swap_myitem", "swap_myitem")
    owner.AnimState:Show("ARM_carry")        
    owner.AnimState:Hide("ARM_normal")    
end    
local function OnUnequip(inst, owner)        
    owner.AnimState:Hide("ARM_carry")        
    owner.AnimState:Show("ARM_normal")    
end

local function fn()
    local inst = CreateEntity()    
    inst.entity:AddTransform()    
    inst.entity:AddAnimState()    
    inst.entity:AddSoundEmitter()  
    
    MakeInventoryPhysics(inst)
    
    --inst.AnimState:SetBank("myitem")    
    --inst.AnimState:SetBuild("myitem")    
    --inst.AnimState:PlayAnimation("idle")
    
    inst:AddComponent("inspectable")
    
    inst:AddComponent("inventoryitem")    
    inst.components.inventoryitem.imagename = "myitem"    
    inst.components.inventoryitem.atlasname = "images/inventoryimages/myitem.xml"    
    
    inst:AddComponent("equippable")    
    inst.components.equippable:SetOnEquip( OnEquip )    
    inst.components.equippable:SetOnUnequip( OnUnequip )
    
    return inst
end

return  Prefab("common/inventory/myitem", fn, assets, prefabs)

 

Do you see the "end" near the bottom? You accidentally merged that with the "return" in the next line. As a result, the compiler did not understand it.

Link to comment
Share on other sites

10 minutes ago, Mobbstar said:

You copy-pasted everything, but in a horrid manner. Here's a properly formatted version:

  Reveal hidden contents

 

local assets =
{
    --Asset("ANIM", "anim/myitem.zip"),    
    --Asset("ANIM", "anim/swap_myitem.zip"),    
    Asset("ATLAS", "images/inventoryimages/myitem.xml"),    
    Asset("IMAGE", "images/inventoryimages/myitem.tex"),
}

prefabs = {}

local function OnEquip(inst, owner)        
    owner.AnimState:OverrideSymbol("swap_object", "swap_myitem", "swap_myitem")
    owner.AnimState:Show("ARM_carry")        
    owner.AnimState:Hide("ARM_normal")    
end    
local function OnUnequip(inst, owner)        
    owner.AnimState:Hide("ARM_carry")        
    owner.AnimState:Show("ARM_normal")    
end

local function fn()
    local inst = CreateEntity()    
    inst.entity:AddTransform()    
    inst.entity:AddAnimState()    
    inst.entity:AddSoundEmitter()  
    
    MakeInventoryPhysics(inst)
    
    --inst.AnimState:SetBank("myitem")    
    --inst.AnimState:SetBuild("myitem")    
    --inst.AnimState:PlayAnimation("idle")
    
    inst:AddComponent("inspectable")
    
    inst:AddComponent("inventoryitem")    
    inst.components.inventoryitem.imagename = "myitem"    
    inst.components.inventoryitem.atlasname = "images/inventoryimages/myitem.xml"    
    
    inst:AddComponent("equippable")    
    inst.components.equippable:SetOnEquip( OnEquip )    
    inst.components.equippable:SetOnUnequip( OnUnequip )
    
    return inst
end

return  Prefab("common/inventory/myitem", fn, assets, prefabs)

 

Do you see the "end" near the bottom? You accidentally merged that with the "return" in the next line. As a result, the compiler did not understand it.

Omg, thank you so much, it works now for me :)

I already thought about that since it makes no sense to put a function into a function, but I thought since it is on a tutorial which is something like a sticky it must be right.

But the way it shows me the code in the box with the "reveal hidden contents" in the tutorial is exactly what I showed you, I just put some returns in it since in the box there were no returns... but I cant believe someone codes without returns? :D Must be something wrong with the "show hidden content"-box.

 

Link to comment
Share on other sites

Hey, its me again.

I tried to follow the tutorial to the end but the last part gives me some trouble.

I created the "swap_myitem.scml" with Spriter changing the pivot and making the picture bigger like in the tutorial.

When I load up the game, it creates the swap_myitem.zip in the "mymod/anim"-folder and in the "mymod/exported/myitem/swap_myitem/"-folder where also the .scml-file is therefore I'd say there is no problem in loading up the .scml-file since it can creates those .zip-files from it,

But I can't see the animation ingame when equipping the item (ground animation fine).

This is my code:

 

local assets =
{
    Asset("ANIM", "anim/myitem.zip"),    
    Asset("ANIM", "anim/swap_myitem.zip"),    
    Asset("ATLAS", "images/inventoryimages/myitem.xml"),    
    Asset("IMAGE", "images/inventoryimages/myitem.tex"),
}

prefabs = {}

local function OnEquip(inst, owner)        
    owner.AnimState:OverrideSymbol("swap_object", "swap_myitem", "swap_myitem")
    owner.AnimState:Show("ARM_carry")        
    owner.AnimState:Hide("ARM_normal") 
end    
local function OnUnequip(inst, owner)        
    owner.AnimState:Hide("ARM_carry")        
    owner.AnimState:Show("ARM_normal")
end

local function fn()
    local inst = CreateEntity()    
    inst.entity:AddTransform()    
    inst.entity:AddAnimState()    
    inst.entity:AddSoundEmitter()  
    
    MakeInventoryPhysics(inst)
    
    inst.AnimState:SetBank("myitem")    
    inst.AnimState:SetBuild("myitem")    
    inst.AnimState:PlayAnimation("idle")
    
    inst:AddComponent("inspectable")
    
    inst:AddComponent("inventoryitem")    
    inst.components.inventoryitem.imagename = "myitem"    
    inst.components.inventoryitem.atlasname = "images/inventoryimages/myitem.xml"    
    
    inst:AddComponent("equippable")    
    inst.components.equippable:SetOnEquip( OnEquip )    
    inst.components.equippable:SetOnUnequip( OnUnequip )
    
    return inst
end

return  Prefab("common/inventory/myitem", fn, assets, prefabs)

Thanks for any help in advance :3

Link to comment
Share on other sites

I tried that and put the .png into 'exported/swap_myitem/swap_myitem' and deleted the .zip-file in the anim folder and the .zip-file in the 'exported/swap_myitem'-folder but then the mod crashes and the cmd says something like "cant find file".

When I put back the .png file into the same folder like the .scml file then the games creates the .zip files but it doesn't show the animation ingame.

Mh..


edit: shouldn't this be easy to reconstruct since I have a tutorial but why I am having such problems with such basic things? :D

Link to comment
Share on other sites

Did you adjust the animation to use the new texture location? You'll need to delete the old sprite, and create a new one. Otherwise, the animation compile will fail (because it's still looking in the old file location), and the ZIP in 'anims' won't be created (which is the missing file reported in the error).

Link to comment
Share on other sites

OMG THIS INDEED WORKED :D

Yeah, I forgot to recreate the sprite after changing location :/

THANK YOU VERY MUCH ! :3


edit: since this thread can be closed, could you maybe help this guy out if you have the time? I don't want to leave him alone :D
 

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...