• How to tell a function to use additional code?
    5 replies, posted
As the title says. What I mean is, if you had something like [CODE] local function useless(extracode) print("dog") extracode print("cat") end local codetable = { print("dammit") //Do other stuff, not just print, a whole RANGE of things that can't simply be toggled by string.find statements and the likes } useless(codetable) [/CODE] How should you be writing extracode (or codetable) in a way that makes it easy for the function to run it as if the extra code that was there the whole time? Shoving the extra code in a table is a pretty dodgy way to do it, is there not something like [CODE] local function useless(codebetweendostuff) print("dog") dostuff codebetweendostuff stopdoingstuff print("cat") end useless(codetable), dostuff print("dammit") stopdoingstuff [/CODE] that you could do? [editline]29th March 2015[/editline] By the way, if you reply, please don't post some tediously long example that'll cause me to have to crawl around the depths of Lua for hours, it'd be very helpful if you referred to this script. Thanks!
I'm trying to use a function to reduce the lines of code necessary, but in doing so, I need aspects of custom code instead of just variables. [editline]29th March 2015[/editline] What should I be doing if not a function for this sort of thing?
So he's talking about Object-oriented programming, or am i completely misunderstanding everything? If so, I'm pretty sure you just include the file you want to use functions from.
[LUA]local function useless(func) print("dog") func() print("cat") end useless(function() print("damnit") end) [/LUA] ?
rejax, what if there are more than one function(s)? Wait, I'm an idiot, It'd just be [CODE] local function useless(func , func2) print("dog") func() print("cat") func2() end useless(function() print("damnit") end, function() print("extra") end) [/CODE] Right? [editline]30th March 2015[/editline] Just checked, WOW, I'm an idiot.
Sorry, you need to Log In to post a reply to this thread.