Jump to content

How to understand functions, how to write them, when you need them and why?


Recommended Posts

Look, I'm not gonna get anywhere if none can give me any explenation about functions that you need to edit an existing part of the game. Say, the Harder recipes mod I made, people gave me a function I needed for the mod to work and I didn't understand crap why I need it. All I knew was that with it the mod worked. Nothing else was added, just me changing the recipes and the function. May be some bits and bobs were added but I am here to understand how the functions work, cause the same function ain't gonna work for editing all other data parts. Any explenation on how the function works? And how do I put two parts of program in modmain so the mod works? Say I want to have my mod to change crafting recipes and change rabbit loot. The recipes work on their own, but no matter what I tried, I could not make the mod change the rabbit loot as well.

And if you're gonna tell me to look at other mods and blah blah blah, then don't post at all, cause it will just not help me, trust me, it won't.

I really do want to make complex mods in future but I need to understand the basics, and it helps me if people give me explenations instead of me just looking all over the mod section to find what I need and understand what I need. So please help if you have even the basic experience in modding.

Link to comment
Share on other sites

:indecisiveness:   but looking into other mods is the basics...(myself i doesn't know anything about making a mod but working for hitd allowed me to understand quickly how to change things in the DS world...)

 

so i can give you an advice

if you wanna bunnyman leave at 1% fur roll , just add that to the modmain(it should work) :

AddPrefabPostInit("bunnyman",function(inst)     inst.components.lootdropper:AddChanceLoot("bedroll_furry",0.01) end)

i have absolutely no idea on how it works but i am sure that will work...only deduction of other mods(like you said it will be useless)

 

edit: and the function i gave you is :

adding some new fonctions to "bunnyman".

i tell it to add new chanceloot to the looting table of the "bunnyman"

and i say to add the furry bedroll at 1%

and i say it to end.

Link to comment
Share on other sites

Look, I'm not gonna get anywhere if none can give me any explenation about functions that you need to edit an existing part of the game. Say, the Harder recipes mod I made, people gave me a function I needed for the mod to work and I didn't understand crap why I need it. All I knew was that with it the mod worked. Nothing else was added, just me changing the recipes and the function. May be some bits and bobs were added but I am here to understand how the functions work, cause the same function ain't gonna work for editing all other data parts. Any explenation on how the function works? And how do I put two parts of program in modmain so the mod works? Say I want to have my mod to change crafting recipes and change rabbit loot. The recipes work on their own, but no matter what I tried, I could not make the mod change the rabbit loot as well.

And if you're gonna tell me to look at other mods and blah blah blah, then don't post at all, cause it will just not help me, trust me, it won't.

I really do want to make complex mods in future but I need to understand the basics, and it helps me if people give me explenations instead of me just looking all over the mod section to find what I need and understand what I need. So please help if you have even the basic experience in modding.

 

Here is a link to the official LUA documentation:  http://www.lua.org/manual/5.2/

Link to comment
Share on other sites

:indecisiveness: but looking into other mods is the basics...(myself i doesn't know anything about making a mod but working for hitd allowed me to understand quickly how to change things in the DS world...)

so i can give you an advice

if you wanna bunnyman leave at 1% fur roll , just add that to the modmain(it should work) :

AddPrefabPostInit("bunnyman",function(inst)     inst.components.lootdropper:AddChanceLoot("bedroll_furry",0.01) end)
i have absolutely no idea on how it works but i am sure that will work...only deduction of other mods(like you said it will be useless)

edit: and the function i gave you is :

adding some new fonctions to "bunnyman".

i tell it to add new chanceloot to the looting table of the "bunnyman"

and i say to add the furry bedroll at 1%

and i say it to end.

That's EXACTLY what I have been doing all this time and it ALWAYS crashes the game. When I said function it's like adding something at the begginning idk why but if I add it to modmain the game doesn't crash. I am not on my PC right now so I can't give you an example of what I mean. All I'm saying is that what you said is what I've been doing and the game just shoots an error at me. I am making mods that are RoG compatible only, but I doubt that's the reason. Btw, you gave me an example of bunnymen drops. What if I wanted Rabbits (jackalos, the small rabbits that you find on the surface world) to have a 50% chance to drop as loot a morsel or a bunny puff? I did what you said there and that just crashes the game. Seriously all this lua business is driving me nuts. I really need one of you guys to help me out, as in I make the changes and develop a mod and you could fix the errors which I can't do! That is what I've been trying to tell and ask all this time! I need an error fixer of some sorts!

Link to comment
Share on other sites

You have to post your source code if you want anybody to fix it for you. Also note that I'm not saying anybody WILL fix it, but nobody is going to do anything if they don't know what you did. Also, as orlan mentioned above, post your log.txt with crash report.

Link to comment
Share on other sites

You have to post your source code if you want anybody to fix it for you. Also note that I'm not saying anybody WILL fix it, but nobody is going to do anything if they don't know what you did. Also, as orlan mentioned above, post your log.txt with crash report.

he is not wanting to others for fixing his bugs, he wants to someone who can explains him how lua works...if i have understood.

Link to comment
Share on other sites

That's EXACTLY what I have been doing all this time and it ALWAYS crashes the game. When I said function it's like adding something at the begginning idk why but if I add it to modmain the game doesn't crash. I am not on my PC right now so I can't give you an example of what I mean. All I'm saying is that what you said is what I've been doing and the game just shoots an error at me. I am making mods that are RoG compatible only, but I doubt that's the reason. Btw, you gave me an example of bunnymen drops. What if I wanted Rabbits (jackalos, the small rabbits that you find on the surface world) to have a 50% chance to drop as loot a morsel or a bunny puff? I did what you said there and that just crashes the game. Seriously all this lua business is driving me nuts. I really need one of you guys to help me out, as in I make the changes and develop a mod and you could fix the errors which I can't do! That is what I've been trying to tell and ask all this time! I need an error fixer of some sorts!

 

 

I think you are looking for a proper LUA editor to help you see mistakes in your code.

 

I use a program called "Notepad++" because it supports many languages, including LUA.  It is helpful to see the code organized and color-coded.  This makes it easy to find errors or mistakes in the code.  Here is a link to that program:

http://notepad-plus-plus.org/download/

Link to comment
Share on other sites

I think you are looking for a proper LUA editor to help you see mistakes in your code.

 

I use a program called "Notepad++" because it supports many languages, including LUA.  It is helpful to see the code organized and color-coded.  This makes it easy to find errors or mistakes in the code.  Here is a link to that program:

http://notepad-plus-plus.org/download/

 

I use that too. It's pretty light, and rather simple, making it perfect for smaller coding projects such as your usual run-on-the-mill mod.

The DS Mod Tools come with an alternative: sublime. It's more complex and has more specific features, making it better for big things like Don't Starve itself, or Up & Away.

Both can highlight Lua syntax, which is essential when programming properly.

 

EDIT: It's always a smart idea to compare your code to similiar one. For example: you want to change jackalope drops, so you should compare to other creatures and how they drop their loot.

Hot tip: It's the lootdropper component :eek2:
Link to comment
Share on other sites

I use that too. It's pretty light, and rather simple, making it perfect for smaller coding projects such as your usual run-on-the-mill mod.

The DS Mod Tools come with an alternative: sublime. It's more complex and has more specific features, making it better for big things like Don't Starve itself, or Up & Away.

Both can highlight Lua syntax, which is essential when programming properly.

EDIT: It's always a smart idea to compare your code to similiar one. For example: you want to change jackalope drops, so you should compare to other creatures and how they drop their loot.

Hot tip: It's the lootdropper component :eek2:

Yeah, but the thing is all I do is just change some stuff, plop it into modmain, save it and run the mod and it always crashes. Why is it that you have to edit and put in stuff you don't give a crap about for your mod not to crash?! I mean according to what you guys are saying all I need for changjng the recipes and loots for stuff is just changing it and adding it to modmain, which is what I do! But it always crashes and I need to sort of hardcore programming mind to understand what I need and it's a DRAG! Hei, you guys are quite good a mods, right?

"Say pal, let's make a deal; I will make mods the way I can. All I'm asking is for you to see why the mods are crashing and edit it. May be that way I will have learnt my lesson by then"

:D

Link to comment
Share on other sites

"Say pal, let's make a deal; I will make mods the way I can. All I'm asking is for you to see why the mods are crashing and edit it. May be that way I will have learnt my lesson by then"

:grin:

Once again, you're going to have to give us something to work with if you want us to debug for you. Some source or a Steam Workshop link... Something.

Link to comment
Share on other sites

Ignore this original post. I added some notes below in a new post.

My experience with creating set pieces is exactly none, so I probably won't be able to help. It looks like it's looking for a rl.lua somewhere and can't find it. Xirmix, is there another mod that you're using as an example for your mod? Does that mod have a rl.lua file anywhere? Perhaps in a scripts/map/static_layouts folder?

For anybody else who's willing, here's the error message for the mod:

 

scripts/map/static_layout.lua:28: module 'map/static_layouts/rl' not found:	no file '../mods/LureplantFarm/scripts/map/static_layouts/rl.lua' (checked with custom loader)	no file 'scripts/map/static_layouts/rl.lua' (checked with custom loader)	no file 'scriptlibs/map/static_layouts/rl.lua' (checked with custom loader)	no file 'scripts/map/static_layouts/rl.lua' (checked with custom loader)	no field package.preload['map/static_layouts/rl']	no file '..\mods\LureplantFarm\scripts\map/static_layouts/rl.lua'	no file 'scripts\map/static_layouts/rl.lua'	no file 'scriptlibs\map/static_layouts/rl.lua'	no file 'scripts/map/static_layouts/rl.lua'LUA ERROR stack traceback:        =[C] in function 'require'        scripts/map/static_layout.lua(28,1) in function 'Get'        ../mods/LureplantFarm/modworldgenmain.lua(4,1) in main chunk        =[C] in function 'xpcall'        scripts/util.lua(439,1) in function 'RunInEnvironment'        scripts/mods.lua(190,1) in function 'InitializeModMain'        scripts/mods.lua(167,1) in function 'LoadMods'        scripts/main.lua(229,1) in function 'ModSafeStartup'        scripts/main.lua(274,1)        =[C] in function 'SetPersistentString'        scripts/mainfunctions.lua(17,1) in function 'SavePersistentString'        scripts/modindex.lua(76,1)        =[C] in function 'GetPersistentString'        scripts/modindex.lua(63,1) in function 'BeginStartupSequence'        scripts/main.lua(273,1) in function 'callback'        scripts/modindex.lua(322,1)        =[C] in function 'GetPersistentString'        scripts/modindex.lua(302,1) in function 'Load'        scripts/main.lua(272,1) in main chunk
and the full log.txt: http://pastebin.com/fydjq8C1
Link to comment
Share on other sites

So it seems Xirmix is following the tutorial for set pieces here: http://forums.kleientertainment.com/topic/32602-tutorial-making-a-custom-setpiece/

There are certain key lines that are required to be changed in modworldgenmain.lua. The person making the tutorial saved his static layout file (scripts/map/static_layout) rl.lua, and you named yours lureplantfarm.lua. In his modworldgenmain file, he references this file (line 4) so you'll need to change the reference to your file.

You might also want to change the "ResearchLab" reference on lines 4 and 10 to something that is more related to your mod. I'd suggest "LureplantFarm" for obvious reasons. This might not be *totally* necessary for your mod to work, but it'll look cleaner for people reading the code.

Third, your lureplantfarm.lua looks like a .xml formatted file that has been renamed to (or saved as) a .lua file. In the export window, look for a dropdown somewhere to choose to save it as a .lua formatted file. Simply changing the file name to .lua might not be enough to save it in the proper format. Unfortunately I don't have access to the dev tools (I'm on a mac), or I'd post a screenshot for you.

I hope this helps!

Link to comment
Share on other sites

Hey, XirmiX, I've come to help.  The main thing that's giving you problems is that you didn't export your Tiled project as a .lua file.  If you need to know how to do that, look at the end of the second half of the Tiled part.  Also, in your modworldgenmain you need to make the setpiece require your static layout (lureplantfarm).  That should be the bulk of the problem.  Try fixing that, and come back if it's still giving you errors.

 

Hope this helps!

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...