Jump to content

Digest October-December

We talk about what was done and updated in the past month. We help keep abreast of events.

December November October

Servers monitoring and the Addons Editor

We present you two legends. All dreams come true.

Servers monitoring The Addons Editor

A statistics bot for Telegram

Convenient analytics right on your phone.

Read more

Game tooltips

Tooltips provide a way for 3rd party fansites and extensions to display detailed information on mouseover.

Read more

The Addons Updater

Let us to introduce the addons updating software and to share the details

Read more Download

Detect Game Version


cristimirt

Recommended Posts

Hi. Simple question, not sure if simple answer as well. How can we detect the game version? I'm interested in detecting if it's pre-4.0 or 4.0+.

You want it not without a reason. So the reason will give you the answer.

Say, if you want to know if it has a certain function to use it, or not, just check if that function does exist.

if common.MyUsefullFunction then
DoStuff()
else
DoOtherStuff()
end

Link to comment
Share on other sites

But if the function does not exist, won't it give an error? Getting an error everytime you load the addon will make the mod.txt pretty big with time.

if common.MyUsefullFunction

Checks if that function exists or not. If not - it will return nil which is same as false to "if" function, so the code after "then" will not be executed, else will trigger instead.

Here's an example:

Once upon a time a function common.GetLocalTime() was moved to mission.GetLocalTime().

Here's how to fix that:

if common.GetLocalTime then 
mission.GetLocalTime = common.GetLocalTime
end

So if you use this script in a 4.0.0 - it will work with no common.GetLocalTime at all. And if you run this in an older version, it will create mission.GetLocalTime and mission.GetLocalTime in your script will work as common.GetLocalTime does.

You may download SetMyFPS and look at first couple of lines. I think you'll understand how does that work.

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

By using our site you agree to the Terms of Use