Fidooop Posted May 31, 2015 Share Posted May 31, 2015 I really need to know how to do this so that I can create any code to run any function I want! including unlocking a character in my mod. Thanks for the help C: Link to comment Share on other sites More sharing options...
Mobbstar Posted May 31, 2015 Share Posted May 31, 2015 In your modmain, you declare a GLOBAL function: GLOBAL.ConsoleCommand1 = function() blablablaend Then type "ConsoleCommand1" to fire that from the console. Link to comment Share on other sites More sharing options...
Fidooop Posted May 31, 2015 Author Share Posted May 31, 2015 I tried that already! D:and just to test I tried it again! G.ConsoleCommand1 = function()G.GetPlayer().components.talker:Say("This is a console command...")end I did this and entered ConsoleCommand1 in the console and it says "attempt to call a nil value" (and if you are wondering I got a line saying "local G = GLOBAL") Link to comment Share on other sites More sharing options...
Corrosive Posted May 31, 2015 Share Posted May 31, 2015 It's not possible for something to be added to the GLOBAL table and for it to disappear once in game. modmain.lua has a environment that's not global, but the GLOBAL table is the global environment. Make sure you don't have any typos. Make sure something else isn't breaking your script. You can verify this by retrieving the global environment from a function that uses it and comparing it to the GLOBAL table(or whatever your reference variable is).local global_env = getfenv(tostring) -- tostring used as example. Any core Lua function will do.print(GLOBAL == G, G == global_env) --> true true Link to comment Share on other sites More sharing options...
Mobbstar Posted May 31, 2015 Share Posted May 31, 2015 I tried that already! D:and just to test I tried it again! G.ConsoleCommand1 = function()G.GetPlayer().components.talker:Say("This is a console command...")end I did this and entered ConsoleCommand1 in the console and it says "attempt to call a nil value" (and if you are wondering I got a line saying "local G = GLOBAL") Are you setting brackets in the command? Link to comment Share on other sites More sharing options...
Fidooop Posted May 31, 2015 Author Share Posted May 31, 2015 It's not possible for something to be added to the GLOBAL table and for it to disappear once in game. modmain.lua has a environment that's not global, but the GLOBAL table is the global environment. Make sure you don't have any typos. Make sure something else isn't breaking your script. You can verify this by retrieving the global environment from a function that uses it and comparing it to the GLOBAL table(or whatever your reference variable is).local global_env = getfenv(tostring) -- tostring used as example. Any core Lua function will do.print(GLOBAL == G, G == global_env) --> true true I will have to fiddle with it later today but yes I do not have any typos at all. Are you able to make a GLOBAL command and make it work in the console? Link to comment Share on other sites More sharing options...
Blueberrys Posted May 31, 2015 Share Posted May 31, 2015 I did this and entered ConsoleCommand1 in the console and it says "attempt to call a nil value" You mean ConsoleCommand1() right? Link to comment Share on other sites More sharing options...
Mobbstar Posted May 31, 2015 Share Posted May 31, 2015 You mean ConsoleCommand1() right? lol I said the same @Fidooop, I went through some of my mods and spontanously called global functions, got no errors other than missing parameters. Can you call other functions without problem? How about global functions from other mods? Link to comment Share on other sites More sharing options...
Fidooop Posted May 31, 2015 Author Share Posted May 31, 2015 You mean ConsoleCommand1() right?OH MY GOD I CAN NOT BELIEVE THAT I FORGOT THE PARENTHESES!!!! D:it's working now >.> Link to comment Share on other sites More sharing options...
Fidooop Posted May 31, 2015 Author Share Posted May 31, 2015 I had the right idea of how I was going to do it from the very start!!!! I just forgot the damned parentheses :C Link to comment Share on other sites More sharing options...
Fidooop Posted May 31, 2015 Author Share Posted May 31, 2015 Are you setting brackets in the command? I feel kinda bad that it looks like I ignored you so I thought I'd clear things up!when you said brackets the first thing that came to mind was [] so I got really confused and skipped over your comment... sorry :Cbut now I know you meant parentheses because I was missing those!!!! D:kinda mad at myself for forgetting the most painfully obvious things in the world!!! :L Link to comment Share on other sites More sharing options...
Corrosive Posted May 31, 2015 Share Posted May 31, 2015 @Fidooop, The parentheses were the first thing I though of, but then I thought "well then he wouldn't be getting the 'attempt to call a nill value' error...." Completely forgot that that's the error you get from the console because it attempts to convert the console string into a function (I believe via loadstring), which fails, and then it tries to execute the function, which is nil. Link to comment Share on other sites More sharing options...
Mobbstar Posted June 1, 2015 Share Posted June 1, 2015 I feel kinda bad that it looks like I ignored you so I thought I'd clear things up!when you said brackets the first thing that came to mind was [] so I got really confused and skipped over your comment... sorry :Cbut now I know you meant parentheses because I was missing those!!!! D:kinda mad at myself for forgetting the most painfully obvious things in the world!!! :L Yeah I'm not the standard modder Next time I make no sense just question me about it! 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.