Java & Beagels - another one of those spacer hang-outs.
Moderators: winston, another_commander
- Arexack_Heretic
- Dangerous Subversive Element
- Posts: 1876
- Joined: Tue Jun 07, 2005 7:32 pm
- Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
- Contact:
Java & Beagels - another one of those spacer hang-outs.
As a friendly forumside addition to the Javascript development wiki.
A place where spacetruckers -unfamilliar with the arcane workings of their drives- can share and request workable code-snippets on Java-script in oolite.
Kind of like the "scripters' cove", but more specialised in J-Scripting.
Not that the wiki is not good, it is a good place to lay out large volumes of detailed background info. Only it is a bit much and (yet) unstructured and incomplete. (at least to my layman sensibilities)
Here practical applications could be discussed and created in-fora.
A place where spacetruckers -unfamilliar with the arcane workings of their drives- can share and request workable code-snippets on Java-script in oolite.
Kind of like the "scripters' cove", but more specialised in J-Scripting.
Not that the wiki is not good, it is a good place to lay out large volumes of detailed background info. Only it is a bit much and (yet) unstructured and incomplete. (at least to my layman sensibilities)
Here practical applications could be discussed and created in-fora.
Riding the Rocket!
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
*thwaps Arexack_Heretic for confusing JavaScript with Java again*
(Also, did you mean beagles or bagels? :-)
(Also, did you mean beagles or bagels? :-)
It’s very structured and mostly complete, but very much reference rather than tutorial. Tutorials would be good to have, but I can’t do everything around here.Arexack_Heretic wrote:Not that the wiki is not good, it is a good place to lay out large volumes of detailed background info. Only it is a bit much and (yet) unstructured and incomplete. (at least to my layman sensibilities)
E-mail: [email protected]
- Arexack_Heretic
- Dangerous Subversive Element
- Posts: 1876
- Joined: Tue Jun 07, 2005 7:32 pm
- Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
- Contact:
Indeed.
Working-man's tutorials are what is required in this place.
The Wiki-great as a reference.
It may be complete for what is available, but not nearly complete as in finished all possible script-possibilities, surely.
I didn't confuse J-script with Java.
I meant Beagels, the dogs, it's a pun on the bagels&beans franchise. obviously you are pulling my leg.
--
My first Java script (attempt) projects::
-Trumble_pusher.OXP make money selling them or their pelts.
Follow the path of Hesperus!!
Expect hefty fines.
-trumble infected- shader?
edit: I don't think I'll persue this further, trumbles would just not be visible on the hull of a ship...only the rare mega-trumble would suffice. (They eat pilots too, not just slaves!) Might salvage for use on cargopod.
-Playing with shaders for hesperus' ship and some animated signs though.
Working-man's tutorials are what is required in this place.
The Wiki-great as a reference.
It may be complete for what is available, but not nearly complete as in finished all possible script-possibilities, surely.
I didn't confuse J-script with Java.
I meant Beagels, the dogs, it's a pun on the bagels&beans franchise. obviously you are pulling my leg.
--
My first Java script (attempt) projects::
-Trumble_pusher.OXP make money selling them or their pelts.
Follow the path of Hesperus!!
Expect hefty fines.
-trumble infected- shader?
edit: I don't think I'll persue this further, trumbles would just not be visible on the hull of a ship...only the rare mega-trumble would suffice. (They eat pilots too, not just slaves!) Might salvage for use on cargopod.
-Playing with shaders for hesperus' ship and some animated signs though.
Last edited by Arexack_Heretic on Fri Oct 12, 2007 4:27 pm, edited 1 time in total.
Riding the Rocket!
- Arexack_Heretic
- Dangerous Subversive Element
- Posts: 1876
- Joined: Tue Jun 07, 2005 7:32 pm
- Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
- Contact:
Maybe more for the suggestions thread...
Is (or could) this be done with java-script?
use a script-method to acces any key in any plist, using the key-name and plist filename as input and returning the key-value(+type)?
(Taking into account complex keyvalues, such as arrays, are excepted.)
use a script-method to acces any key in any plist, using the key-name and plist filename as input and returning the key-value(+type)?
(Taking into account complex keyvalues, such as arrays, are excepted.)
Riding the Rocket!
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
Currently, no, except that the debug console script can access the contents of debugConfig.plist. On the other hand, it does have access to dictionaries and arrays, no problem there.
I’m somewhat wary of letting scripts play around with files. If you could be more specific with what you want, we might be able to work something out. I considered the possibility of allowing each script to have a configuration plist attached to it, but then, you can declare plist-like structures (actually called property lists) in JavaScript:
On the third hand, having a script-accessible dictionary attached to ship types could be useful.
Again, I might be able to be more helpful if you had more specific needs.
I’m somewhat wary of letting scripts play around with files. If you could be more specific with what you want, we might be able to work something out. I considered the possibility of allowing each script to have a configuration plist attached to it, but then, you can declare plist-like structures (actually called property lists) in JavaScript:
Code: Select all
this.config = {
someString: "Foo",
someArray: [ "item0", "item1"]
}
Log(this.config.someArray[1] == "item1") // logs "true"
Again, I might be able to be more helpful if you had more specific needs.
E-mail: [email protected]
- Arexack_Heretic
- Dangerous Subversive Element
- Posts: 1876
- Joined: Tue Jun 07, 2005 7:32 pm
- Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
- Contact:
Not really specific needs from my end. (Or I have forgotten the reason for asking this) Just seems usefull for some applications to flexibly retrieve information from various sources, not just the descriptive ones.
No intention of editing files by script, just accessing the contents.
Such as you stated plists and such.
(Don't know what you are holding in that thrid hand of yours mate. )
AI's could use access to shipdate for example to finetune responces or behaviours on that info.
No intention of editing files by script, just accessing the contents.
Such as you stated plists and such.
(Don't know what you are holding in that thrid hand of yours mate. )
AI's could use access to shipdate for example to finetune responces or behaviours on that info.
Riding the Rocket!
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
When it comes the shipdata entries, I think it’s better for scripts to get their information from the ship entity itself. A lot of information is already exposed. There are probably more stats that could usefully be there, but I’ve got to save some stuff for the next version, right? ;-)
But I think I’ll add a script_info dictionary to shipdata, exposed to scripts as Ship.scriptInfo. For instance:
Note that entries in script_info will constitute a shared namespace, so they should have unique names.
But I think I’ll add a script_info dictionary to shipdata, exposed to scripts as Ship.scriptInfo. For instance:
Code: Select all
// Shipdata.plist entry
script_info = { "ahruman-scariness-factor" = 2.5; };
// script
if (ship.scriptInfo["ahruman-scariness-factor"] != undefined && ship.scriptInfo["ahruman-scariness-factor"] > 2) ...
E-mail: [email protected]
- Arexack_Heretic
- Dangerous Subversive Element
- Posts: 1876
- Joined: Tue Jun 07, 2005 7:32 pm
- Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
- Contact:
So this enables one to enable any desirable 'my-info' carried by the entity?
Which then in turn can be accesed by AI specifically lookin for this info. (without something looking for and using the data, it would do exactly nothing. except use a few bytes of memspace.)
a "ships' handbag" as it were, where you keep stuff that is essentially useless untill you need it. (and even then is usually not essential for survival)
Which then in turn can be accesed by AI specifically lookin for this info. (without something looking for and using the data, it would do exactly nothing. except use a few bytes of memspace.)
a "ships' handbag" as it were, where you keep stuff that is essentially useless untill you need it. (and even then is usually not essential for survival)
Riding the Rocket!
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
The information is available to any JavaScript script, but not to AIs. The new ship scripts do not currently replace the AI state machines.
E-mail: [email protected]
- Arexack_Heretic
- Dangerous Subversive Element
- Posts: 1876
- Joined: Tue Jun 07, 2005 7:32 pm
- Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
- Contact:
- Arexack_Heretic
- Dangerous Subversive Element
- Posts: 1876
- Joined: Tue Jun 07, 2005 7:32 pm
- Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
- Contact:
OK been rummaging (or munging) through the various sources of java wisdom in order to get a simple script to work.
Goal: when in flight, periodically check and display the number of trumbles. (but only if changed)
Q: What is the best way to mimic?
Do I use
or a double
or something different altogether?
such as:
CURRENTLY HAVE:
The problem is in the timer, which is not yet defined.
i'll try the depricated 'tickle' event in the meantime.
Goal: when in flight, periodically check and display the number of trumbles. (but only if changed)
Q: What is the best way to mimic
Code: Select all
status_string equal IN_FLIGHT
Do I use
Code: Select all
if (player.status == STATUS_IN_FLIGHT)
Code: Select all
this.didExitWitchSpace = function() {} ;
this.didLaunch = function() {};
such as:
Code: Select all
if (boolean docked);
else {};
Code: Select all
this.name = "JavaScript-trumblecheck";
this.author = "Arnoud van Marion";
this.copyright = "This work is hereby placed in the public domain.";
this.description = "checks the number of trumbles and displays a consolemessage";
this.version = "1.69.1";
// Start timer after launch
this.hasLaunched = function() {start(timerAH)};
// Stop timer when docking
this.isDocking = function() {stop(timerAH)};
// every 30 seconds do check
this.timerAH = new Timer(this, function() {this.trumblecheck}, 30, 30)
// check 1: has trumble? 2:isNOTdocked? 3:Changed since last count?
this.trumblecheck = function()
{
if (player.hasEquipment(EQ_TRUMBLE))
{
Log("Oh noes, I has a trumble!");
if (player.docked) Log("I am docked");
else
{
Log("I am not docked");
var trumbleNumber = missionVariables.trumbleNumber;
Log("I has [player.trumbleCount] trumbles");
if (player.trumbleCount != trumbleNumber)
{
if (player.trumbleCount <= trumbleNumber)
{
(consoleMessage("Trumbles decreasing: [trumbleNumber] remaining"));
(missionVariables.trumbleNumber = player.trumbleCount);
};
if (player.trumbleCount >= trumbleNumber)
{
(consoleMessage("Trumbles multiplying: increased to [trumbleNumber]"));
(missionVariables.trumbleNumber = player.trumbleCount);
}
}
}
}
}
i'll try the depricated 'tickle' event in the meantime.
Riding the Rocket!
- Arexack_Heretic
- Dangerous Subversive Element
- Posts: 1876
- Joined: Tue Jun 07, 2005 7:32 pm
- Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
- Contact:
With tickle iso timer:
no error messages, but also no actions in-game.
no error messages, but also no actions in-game.
Code: Select all
this.name = "JavaScript-trumblecheck";
this.author = "Arnoud van Marion";
this.copyright = "This work is hereby placed in the public domain.";
this.description = "checks the number of trumbles and displays a consolemessage";
this.version = "1.69.1";
// timer not yet working...
// Start timer after launch
//this.hasLaunched = function() {start(timerAH)};
// Stop timer when docking
//this.isDocking = function() {stop(timerAH)};
// every 30 seconds do check
//this.timerAH = new Timer(this, function() {this.trumblecheck}, 30, 30)
//using tickle in place of timer untill it works (expected: v1.70)
this.tickle = function(status)
{
Log("[this.name]: that tickles");
// check 1: has trumble? 2:isNOTdocked? 3:Changed since last count?
// can remove check for being docked if 'tickle' checks this.
this.trumblecheck = function()
{
if (player.hasEquipment(EQ_TRUMBLE))
{
Log("Oh noes, I has a trumble!");
if (player.docked) Log("I am docked");
else
{
Log("I am not docked");
var trumbleNumber = missionVariables.trumbleNumber;
Log("I has [player.trumbleCount] trumbles");
if (player.trumbleCount != trumbleNumber)
{
if (player.trumbleCount <= trumbleNumber)
{
(consoleMessage("Trumbles decreasing: [trumbleNumber] remaining"));
(missionVariables.trumbleNumber = player.trumbleCount);
};
if (player.trumbleCount >= trumbleNumber)
{
(consoleMessage("Trumbles multiplying: increased to [trumbleNumber]"));
(missionVariables.trumbleNumber = player.trumbleCount);
}
}
}
}
}
}
Riding the Rocket!
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
You were right to consider timers first, and they will be the right way to do this in 1.70 and later. In 1.69, tickle() is what there is.
The reason nothing happens is that you’re not calling the function trumblecheck. If you comment out the line “ this.trumblecheck = function()”, it should work. Apart from the other errors noted below.
A more efficient approach, though, would be to only do the periodic trumble checking when the player actually has trumbles (regardless of whether you’re using tickle or timers).
Errors in your code, apart from not being called:
The reason nothing happens is that you’re not calling the function trumblecheck. If you comment out the line “ this.trumblecheck = function()”, it should work. Apart from the other errors noted below.
A more efficient approach, though, would be to only do the periodic trumble checking when the player actually has trumbles (regardless of whether you’re using tickle or timers).
Code: Select all
this.trumbleCheck = function()
{
// do check here
}
this.startLookingForTrumbles = function()
{
this.tickle = this.trumbleCheck
// OR timerAH.start()
}
this.stopLookingForTrumbles = function()
{
delete this.tickle;
// OR timerAH.stop()
}
this.didLaunch = function() // not hasLaunched
{
if (player.hasEquipment("EQ_TRUMBLE"))
{
this. startLookingForTrumbles()
}
else
{
this.stopLookingForTrumbles()
}
}
this.didScoop = this.didLaunch; // Not called in 1.69, so this version wouldn’t notice trumbes from canisters until the next launch.
this.reset = this.stopLookingForTrumbles // Redundant if timers are being used, but not harmful.
- you need quotation marks around "EQ_TRUMBLE".
- Change missionVariables.trumbleNumber to missionVarables.AH_trumbleNumber or similar for uniqueness.
- var trumbleNumber = missionVariables.trumbleNumber should be:This is necessary for two reasons: one, foo = bar, where bar is undefined, is an error. Also, mission variables are always strings, so you need to convert to a number (integer). The first issue will (probably) be resolved in future by making unused mission variables null rather than undefined, but you’ll still need the check in this case because parseInt(null) is NaN (“not a number”).
Code: Select all
var trumbleNumber = 0 if (missionVarables.AH_trumbleNumber != undefined) { trumbleNumber = parseInt(missionVarables.AH_trumbleNumber) }
E-mail: [email protected]
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
Oh, yeah.
isn’t going to anything useful. For one, you can’t do string substitutions that way in JavaScript. For another, there is no player.trumbleCount property. You can, however, get the value using player.call("trumbleCount") – but remember, whenever you need to use foo.call(), file a scripting request for a JavaScript equivalent.
Anyway, this should work:
Code: Select all
Log("I has [player.trumbleCount] trumbles");
if (player.trumbleCount != trumbleNumber)
Anyway, this should work:
Code: Select all
let trumbleCount = player.call("trumbleCount")
Log("I has " + trumbleCount + " trumbes")
if (trumbleCount != trumbleNumber)
E-mail: [email protected]