Greetings :)
From inside modulemining.js i want to send a message to the player, but console.print or document.write does not seem to work.
How can i send a notification (including the value of variables from mentioned script) to the screen of the player?
I have the notification working in one of my beta mods. This is the code i use:
var playerName = game.GetShipOwner(args.caster_id);
var faction = relations.GetShipFaction(args.ship_id);
if (faction == "pirates" && ship.HasCargoAmount(args.caster_id, "goods_license", 1))
{
game.SendNotification(playerName, "Nice Kill!", "Score one for the good guys! Here is your licensed reward money and exp");
player.AddMoney(playerName, totalReward);
player.AddExperience(playerName, totalRewardexp);
}
Thank you, jeeplaw :)
However, i think i need to be more precise, as i do not have a valid clue how to implement your solution.
Basically, i want to put what is in those console.Print messages into game.SendNotification messages.
So in ModuleMining.js in function OnUpdateCache(args) i changed this:
// console.Print("Mining range modifier current: " + mining_range_modifier);
into this:
game.SendNotification(player_name, "Current Mining Range Modifier: " + mining_range_modifier);
and after the using part (outside of and above function OnUpdateCache(args) i added this:
var player_ship = args.ship_id;
var player_name = game.GetShipOwner(args.ship_id);
Now i always get this error "[ERR] Script exception! ReferenceError: args is not defined at ModuleMining:21"
and it refers me to the var player_ship = args.ship_id; line.
What am i doing wrong?
Alright, this is now a happy ManMachine :D
I replaced
console.Print("Mining range modifier current: " + mining_range_modifier);
with
game.SendNotificationError(game.GetShipOwner(args.ship_id), "Mining range modifier current: " + mining_range_modifier);
and it works!
Thanks go to jeeplaw for helping in the first place and Maroku for the final solution :)
Hm... Thinking about this, it would make for a good, easy, fast debug-system, where information from a script can be shown right on the screen.
I never saw anything anywhere when i uncommented those "//console.print"-lines and it could be used to debug a specific point in the code,
unlike the general debug setting which just produces a massive amount of text in the logfiles.
Maybe one of You moderators could change the topic of this thread to something like "point-specific debugging made easy" or so and make it sticky?
(i think i cannot change the topic-name myself)
I think it would be a big help for beginners like me who know how to change stuff inside the code, but not really (yet) know how to program.
It sure is a bigbig help for me, as now i can practically turn any of those //console.print-lines in the code into lines that actually show me what happens,
when i change things (for good or for worse).