t0r3 Posted March 21, 2019 Share Posted March 21, 2019 Hey Started learning how to script a few days ago, and I am now in need of some help I know how to display for how long the script has been running / and how many levels I have gained. How would I go about counting, logging and displaying f.ex amount of logs chopped since I started the script? - what code could I use? Thanks Quote Link to comment Share on other sites More sharing options...
Czar Posted March 21, 2019 Share Posted March 21, 2019 (edited) Well first you gotta determine how would the script know when you woodcutted? One way would be to read in-game messages e.g. 'you chopped the tree and got some logs' or w/e it is, then add on to a simple int, e.g. treesChopped++; So you would implement something like // declare this outside of a method private int treesChopped; // add this if you don't already have it, on your main script class public void onMessage(Message m) { if (m.getMessage().contains("got some logs")) { treesChopped++; } } Of course it is basic (no null-checks, doesn't check if messages are from a player or the game) and isn't the correct message (I forget the exact message) so you gotta edit the message and it should be fine. But the idea is there. Edited March 21, 2019 by Czar 2 Quote Link to comment Share on other sites More sharing options...
t0r3 Posted March 21, 2019 Author Share Posted March 21, 2019 3 hours ago, Czar said: Well first you gotta determine how would the script know when you woodcutted? One way would be to read in-game messages e.g. 'you chopped the tree and got some logs' or w/e it is, then add on to a simple int, e.g. treesChopped++; So you would implement something like // declare this outside of a method private int treesChopped; // add this if you don't already have it, on your main script class public void onMessage(Message m) { if (m.getMessage().contains("got some logs")) { treesChopped++; } } Of course it is basic (no null-checks, doesn't check if messages are from a player or the game) and isn't the correct message (I forget the exact message) so you gotta edit the message and it should be fine. But the idea is there. Hey, thanks! I like how many of the main scripters here are so friendly in this community put it like this ; public void onMessage(Message m) { if (getChatbox().getMessages()) { fishCount++; } } I need to have a message type first in the parameters for getMessages, - what messagetype is the string "You caught some shrimp/anchovies"? Sry if it is obvious haha Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted March 21, 2019 Share Posted March 21, 2019 28 minutes ago, t0r3 said: Hey, thanks! I like how many of the main scripters here are so friendly in this community put it like this ; public void onMessage(Message m) { if (getChatbox().getMessages()) { fishCount++; } } I need to have a message type first in the parameters for getMessages, - what messagetype is the string "You caught some shrimp/anchovies"? Sry if it is obvious haha I haven't scripted for a while, but I believe it's GAME. You don't need to do getChatbox().getMessages() either. 1 Quote Link to comment Share on other sites More sharing options...
t0r3 Posted March 21, 2019 Author Share Posted March 21, 2019 (edited) @HeyImJamie @Czar Got it working! Now paint shows how many shrimps and how many anchovies I caught private int shrimpCount; private int anchoviesCount; public void onMessage(Message m) { if (m.getMessage().contains("You catch some shrimps.")) { shrimpCount++; } else if (m.getMessage().contains("You catch some anchovies.")) { anchoviesCount++; } } Thank you so much! This is fun Edited March 21, 2019 by t0r3 2 Quote Link to comment Share on other sites More sharing options...