Static functions?
Re: Static functions?
I've also noticed the slight degradation in error reporting when using closures, that's probably something to do with the way JS API's include() function is working?
Anyway, closures are standard JS, and the sandbox approach is generally considered best practice (which is why practically everyone uses it). I wouldn't want the API to try and invent it's own way of doing sandboxing as that would be very confusing indeed.
Instead, I'd prefer time be spent on finding out what's causing degradation of errors that occur in closures in included scripts.
Anyway, closures are standard JS, and the sandbox approach is generally considered best practice (which is why practically everyone uses it). I wouldn't want the API to try and invent it's own way of doing sandboxing as that would be very confusing indeed.
Instead, I'd prefer time be spent on finding out what's causing degradation of errors that occur in closures in included scripts.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
-- https://warzone.atlassian.net/wiki/display/GO
Re: Static functions?
A few more little benefits from splitting files include being able to see github changelogs for separate files (AI aspects!) and probably easily re-use modules in other projects (dreaming ...).
Maps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam
Re: Static functions?
NoQ, could you define those "AI aspects"? That would make things clear also for me.
Nadszedł już czas, najwyższy czas, nienawiść zniszczyć w sobie.
The time has come, the high time, to destroy hatred in oneself.
Beware! Mad Qt Evangelist.
The time has come, the high time, to destroy hatred in oneself.
Beware! Mad Qt Evangelist.
Re: Static functions?
Building structures, producing tanks, researching technologies, tactics and micromanagement, etc.
Maps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam
Re: Static functions?
OK, so common parts for all "profiles"?
Then I wouldn't split them, separate changelog for each file is minor benefit, you could simply use prefixes in commits messages to mark these changing specific aspects.
Then I wouldn't split them, separate changelog for each file is minor benefit, you could simply use prefixes in commits messages to mark these changing specific aspects.
Nadszedł już czas, najwyższy czas, nienawiść zniszczyć w sobie.
The time has come, the high time, to destroy hatred in oneself.
Beware! Mad Qt Evangelist.
The time has come, the high time, to destroy hatred in oneself.
Beware! Mad Qt Evangelist.
Re: Static functions?
For people wanting to customise nullbot to their needs, not having to wade through a massive file makes life much easier, and also reduces the chances of them breaking stuff when they make edits.
Also, at some point it may be possible to parse some of the files to display stats or diagrams showing how that particular file is configured.
In any case, NullBot is already split in to several smaller files and has been for many versions and that approach has worked well so far...
Also, at some point it may be possible to parse some of the files to display stats or diagrams showing how that particular file is configured.
In any case, NullBot is already split in to several smaller files and has been for many versions and that approach has worked well so far...
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
-- https://warzone.atlassian.net/wiki/display/GO
Re: Static functions?
Well, there is always way like this:
http://www.sqlite.org/amalgamation.html
(for releases to be included in game only)
http://www.sqlite.org/amalgamation.html
(for releases to be included in game only)
Nadszedł już czas, najwyższy czas, nienawiść zniszczyć w sobie.
The time has come, the high time, to destroy hatred in oneself.
Beware! Mad Qt Evangelist.
The time has come, the high time, to destroy hatred in oneself.
Beware! Mad Qt Evangelist.
Re: Static functions?
Yes, but what's the point? include() pulls in the files nice and easy and by time game starts warzone is looking at a single js file.
Also, the includes are used across several flavours/personalities of nullbot. So if some auto-merge thing was used during build process, you'd just end up with big dollops of code duplicated across several variants of the AI.
I really can't see any problem with using the includes, it's a great way of doing things. There's certainly no benefit whatsoever in merging the includes.
Also, the includes are used across several flavours/personalities of nullbot. So if some auto-merge thing was used during build process, you'd just end up with big dollops of code duplicated across several variants of the AI.
I really can't see any problem with using the includes, it's a great way of doing things. There's certainly no benefit whatsoever in merging the includes.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
-- https://warzone.atlassian.net/wiki/display/GO
Re: Static functions?
aubergine, this is example, it doesn't (yet) apply to WZ addons.
Nadszedł już czas, najwyższy czas, nienawiść zniszczyć w sobie.
The time has come, the high time, to destroy hatred in oneself.
Beware! Mad Qt Evangelist.
The time has come, the high time, to destroy hatred in oneself.
Beware! Mad Qt Evangelist.
Re: Static functions?
The addition way to clear scope is using modules:NoQ wrote:Building structures, producing tanks, researching technologies, tactics and micromanagement, etc.
var utils = function() {} # just container
utils.foo = function() { ...
utils.boo = function() { ....
It that way you have only 'utils' name in global scope.
PS. never trust c++ programmers about file size, many cpp files in src dir is over 2000 K lines and one OVER9000 Some rumors in internat says file over 1000 is bad.
http://addons.wz2100.net/ developer
Re: Static functions?
Duha, bad for developers, good for compilers (unless they are big due to something being done wrong).
EOT
EOT
Nadszedł już czas, najwyższy czas, nienawiść zniszczyć w sobie.
The time has come, the high time, to destroy hatred in oneself.
Beware! Mad Qt Evangelist.
The time has come, the high time, to destroy hatred in oneself.
Beware! Mad Qt Evangelist.
Re: Static functions?
I was considering this, but it makes the code longer and harder to read (: Yet, one of the benefits would be that you always know where to look for a certain function's body.Duha wrote:The addition way to clear scope is using modules:
Maps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam
Re: Static functions?
You can use namespaces (or modules as Duha calls them) and sandboxes together if desired. So you could do something like this:
Code: Select all
// main script
this.NullBot = function(){}; // you can access NullBot from anywhere, it's on the global object
include("path/to/whatever.js");
Nullbot.foo(); // "hello"
Code: Select all
// whatever.js
(function(_global) {
// private
var msg = "hello";
// public
// NullBot namespace can be accessed from anywhere, even in this sandbox,
// so no need to prefix with _global.
NullBot.foo = function() { console(msg); }
})(this);
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
-- https://warzone.atlassian.net/wiki/display/GO
Re: Static functions?
IMHO code should be written for reading. (code for compiler is ugly and hard mantained).Emdek wrote:Duha, bad for developers, good for compilers (unless they are big due to something being done wrong).
EOT
In some cases it is better to read (especially if you not author). This is good for reusable modules.NoQ wrote:I was considering this, but it makes the code longer and harder to read (: Yet, one of the benefits would be that you always know where to look for a certain function's body.Duha wrote:The addition way to clear scope is using modules:
http://addons.wz2100.net/ developer
Re: Static functions?
Now for the "real" arguments.
If i dosuperFunction writes empty string to debug, but ultraFunction writes "ultraFunction".
the same code, being advanced enough, can work completely differently in static and global functions with this sandboxing technique.
Background:
If i do
Code: Select all
_global.superFunction = function() {
megaFunction();
}
function ultraFunction() {
megaFunction();
}
function megaFunction() {
debug(arguments.callee.caller.name);
}
the same code, being advanced enough, can work completely differently in static and global functions with this sandboxing technique.
Background:
Spoiler:
Maps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam