AggrorJorn Posted March 12, 2010 Share Posted March 12, 2010 I always wondered what someone can do to keep his main code as clean as possible. I think I can do a lot cleaning by creating functions but I seem to do something wrong. main loop example: if KeyHit(KEY_E)==1 then do all kinds of stuff... end I want to replace this code with a function. The function is located in another file (MygameFunctions.lua). I've have included the folder of the lua file. Lets say I use this function to replace the code above: function UpdateMission () . Is this a correct way of calling the fuction in the other lua file? The function inside Lua file would look like this: function UpdateMission () if KeyHit(KEY_E)==1 then do all kinds of stuff... end end Quote Link to comment Share on other sites More sharing options...
macklebee Posted March 12, 2010 Share Posted March 12, 2010 If I am following you correctly then this is inside the MygameFunctions.lua: function UpdateMission() if KeyHit(KEY_E)==1 then do all kinds of stuff... end end and then to call the function in your game script you are doing this in the beginning: require("scripts/whereever/MygameFunctions") and have this in your main loop: UpdateMission() If thats what you are doing it should work, as long as the gamescript or MygameFunctions.lua has the keycodes included... its essentially what all of the other separate standard scripts are doing as well. 1 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 12, 2010 Author Share Posted March 12, 2010 Thanks Macklebee. Thats what I needed to know. What do you mean with "keycodes included". You mean that I have 'Require gamescript in the beginning'? +1 Quote Link to comment Share on other sites More sharing options...
macklebee Posted March 12, 2010 Share Posted March 12, 2010 Thanks Macklebee. Thats what I needed to know. What do you mean with "keycodes included". You mean that I have 'Require gamescript in the beginning'? +1 I mean for the KEY_E to be recognized you will also need this in either the beginning of the gamescript or the MygameFunctions.lua: require("Scripts/constants/keycodes") or require("Scripts/constants/engine_const") which has the keycodes in it as well along with other info concerning entities, buffers, etc... Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 13, 2010 Author Share Posted March 13, 2010 ah good to know. thanks for the explanation Quote Link to comment Share on other sites More sharing options...
macklebee Posted March 13, 2010 Share Posted March 13, 2010 ah good to know. thanks for the explanation np... glad to help Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Pancakes Posted March 19, 2010 Share Posted March 19, 2010 this is good stuff right here Quote Core I5 2.67 / 16GB RAM / GTX 670 Zbrush/ Blender / Photoshop CS6 / Renoise / Genetica / Leadwerks 3 Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.