Author Topic: On-Board Messagesystem  (Read 1420 times)

MenschMaschine

  • Full Member
  • ***
  • Posts: 104
    • View Profile
On-Board Messagesystem
« on: April 15, 2015, 03:28:48 am »
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?
No Berries!

jeeplaw

  • Newbie
  • *
  • Posts: 46
    • View Profile
Re: On-Board Messagesystem
« Reply #1 on: April 15, 2015, 08:04:51 am »
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);
      
      
    }

MenschMaschine

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: On-Board Messagesystem
« Reply #2 on: April 15, 2015, 10:21:03 am »
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?
No Berries!

MenschMaschine

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: On-Board Messagesystem
« Reply #3 on: April 16, 2015, 04:04:47 am »
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 :)
No Berries!

MenschMaschine

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: On-Board Messagesystem
« Reply #4 on: April 16, 2015, 04:14:34 am »
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).
No Berries!