Jump to content

[Solved] - Cleaning up the main loop


AggrorJorn
 Share

Recommended Posts

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

Link to comment
Share on other sites

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.

  • Upvote 1

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

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...

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...