Category | Scripting |
Created | 26.02.2019 19:40 |
Kaj-aage Henneberg (kahfs) | 26.02.2019 19:40 |
---|---|
Hello, I'm trying to learn some lua programming but I'm confused about the use of names in calls to FS functions. An example. I have a table with some fruit names. Fruits = {"WHEAT", "BARLEY", "OAT", "COTTON", "CANOLA", "SUNFLOWER"}; If I want to get the fillType of a certain crop, I write: iFillType = g_fillTypeManager:getFillTypeIndexByName('WHEAT'); In the first line, names are enclosed by " ". In the latter by ' '. I thought I could write: iFillType = g_fillTypeManager:getFillTypeIndexByName(Fruits[1]); but that doesn't work. How can I save crop names in a list and use them in a function call? Regards. |
Paul Laverick (paullaverick) | 26.02.2019 23:51 |
---|---|
Hi. I tried your bits of code and they seemed to work. I used this print (g_fillTypeManager:getFillTypeIndexByName('WHEAT')) Fruits = {"WHEAT", "BARLEY", "OAT", "COTTON", "CANOLA", "SUNFLOWER"}; print (g_fillTypeManager:getFillTypeIndexByName(Fruits[1])) print "---" and got this in the log 2019-02-26 22:48 2.000000 2019-02-26 22:48 2.000000 2019-02-26 22:48 --- You are getting the filltype index, is that what you need? |
Kaj-aage Henneberg (kahfs) | 27.02.2019 17:32 |
---|---|
Unbelievable. I tried this two months ago, and I got an error. Now it works. This allows a much more efficient script using for loops. I'm, writing a mod assigning new values to a range of game parameters and have to access fillTypes, fruitTypes,animals, fields, husbandries, etc. It was not very elegant having to hard code a name into a function call. Storing names in a list is much more elegant. Thank you so much Paul Laverick for helping me out with this. |
Note: Log in to post. Create a new account here.