Volgera Posted May 20, 2015 Share Posted May 20, 2015 I have a weird issue where I can't access some of the tech tabs to put in recipes. For example, I can't call the "REFINEMENT" tab or the "TOOLS" tab, even though I have called the GLOBAL.RECIPETABS... but I can access the WAR tab. Does anyone know why? Link to comment Share on other sites More sharing options...
Corrosive Posted May 21, 2015 Share Posted May 21, 2015 @Volgera, (this is just pedantic but you arent "calling" a "tab" -- you are "accessing" or "referencing" a "field" or "index" or "element" or "value" of the GLOBAL.RECIPETABS table) Anyhoo! There is close to zero possibility that you are unable to access one or more but not all elements of GLOBAL.RECIPETABS... But you didn't post any code, so it's hard to say why you're encountering a problem! It's kinda like going up to someone and saying "this other guy doesn't understand me when I tell him something!" I gotta know what you're telling him to figure out why that is Link to comment Share on other sites More sharing options...
Volgera Posted May 21, 2015 Author Share Posted May 21, 2015 @Corrosive all right! I'm not much of a coder just yet, so I'm not all too familiar with all the right terms I'll keep it in mind. anyway, here's the code that I'm using to access GLOBAL.RECIPES;local RECIPETABS = GLOBAL.RECIPETABSlocal craftironbar = Recipe("ironbar", { ironbar, Ingredient("coalore", 4), Ingredient("ironore", 2)}, RECIPETABS.WAR, {SCIENCE = 2} )craftironbar.atlas = "images/inventoryimages/ironbar.xml"now, that says "WAR" because it's currently the one of the only tabs I can access. Below is an image of all options I get when I enter the letter T to find TOOLS. and whenever I try to load the code in-game when I put "TOOLS" there, I get this error: so yeah, I have a feeling I might be leaving out some information I should've added in my code... but I'd have no idea what :s Link to comment Share on other sites More sharing options...
Corrosive Posted May 21, 2015 Share Posted May 21, 2015 @Volgera, Hah! So apparently my comment about the definition of what "calling" means was entirely relevant to your issue. FWIW, if you rely on an IDE's code completion for Lua, you are going to get pretty frustrated. Lua isn't a 'strongly typed' language, at least in the object-oriented sense. With a strongly typed language, an IDE will see that you have an object of a specific type, know what members(properties, methods, etc) belong to that type, and any other type that it inherits from, and will be able to suggest them. In Lua there is only one data type: table, which can hold anything in any index. Local variables are similarly flexible, and any type of data can be stored in a variable, and later replaced. Which makes something like this really hard(if not impossible) for the IDE to understand:function GetFruit(type) if type == "banana" then return { "table with a banana on it" } else return { "table with a persimmon on it" }endpiece_of_fruit = GetFruit(some_variable)No IDE knows what type of fruit is going to be returned by the GetFruit function, so they wont be able to suggest anything. One strategy IDEs use however, is to suggest things that it sees being used at some point. But that doesn't guarantee that it will know many of the possible options. It doesn't even guarantee that the field will even exist, since the variable might be completely different by then. Another is to suggest common properties. I believe that's why yours is suggesting THIS and This(which is many language's equivalent to Lua's "self"). SO! That said, there's a kinda confusing reason that you're getting that error. Remember how I said that "calling" means to "execute a function"? The error says that you are trying to call a field that contains a table value. This is the error you get when you try to execute a table as if it were a function. There are three ways to tell Lua to call a function. The first is the standard way, which uses parentheses:SomeFunction( <any number of arguments can go here, comma separated> )The second and third ways work only if you are passing a SINGLE argument. You can pass it a string like so:-- this:SomeFunction"I'm a string"-- orSomeFunction "I'm a string" -- spacing doesn't matter-- is the same as this:SomeFunction("I'm a string")and you can pass it a table like so: -- this:SomeFunction{ field = value, field2 = value2, etc = etc }-- orSomeFunction { -- again, spacing doesn't matter field = value, field2 = value2, etc = etc}-- is the same as:SomeFunction({field = value, field2 = value2, etc = etc})Presumably when you put "TOOLS" in there, it looked like this: ..... Ingredient("ironore", 2)}, RECIPETABS.TOOLS {SCIENCE = 2} )Notice the lack of comma after TOOLS? Instead of treating {SCIENCE = 2} as an argument for the Recipe function, it assumed you were using the last syntax above, and you wanted to pass it as the argument to RECIPETABS.TOOLS(which is a table, not a function). Link to comment Share on other sites More sharing options...
Volgera Posted May 21, 2015 Author Share Posted May 21, 2015 @Corrosive, ah! of course! Thanks a lot for all this valuable information, that explains a lot about some questions I had about coding in lua! The issue is also fixed now (wauw I never even noticed I didn't put a comma there anymore), thanks a lot! Link to comment Share on other sites More sharing options...
Recommended Posts
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.