Everything posted by fixthissite
-
Singleton JFrame not appearing on script start
Prevents inconsistencies. But can be a victim to deserialization (you can serialize without needing to implement serializable by declaring readObject and writeObject methods) and instantiation through reflection. Not to mention, public enum Singleton { INSTANCE; } Is a lot let verbose ;)
-
Programmers who use twitter (or don't, doesn't matter...)
I post programming tips on my twitter, so feel free to follow me or check in every now and then to see if I've posted anything new. You could learn some neat stuff. @emigh_scott If you post neat stuff, let me know. Im always looking for neat stuff. If you know anyone who may be a supplier of neat stuff, let me know. Neat stuff, guys. Keep up the good work
-
Singleton JFrame not appearing on script start
Making it return new GUI() doesn't ensure only a single instance of that class will exist within memory. One of the most important aspects is ensuring new GUI is only called once. Lazy initialization would make that suggestion more reasonable: public static GUI getInstance() { if(instance == null) instance = new GUI(); return instance; } But honestly, creating singletons using classes is extremely tedious, as well as dangerous. For example, 2 threads call getInstance(). First thread sees that instance null, initializes it. Right after thread 1 sees that instance is null, but before it has a chance to initialize it, thread 2 could also see that it's null and attempt to initialize. To prevent this, you'd need double check locking. But even that doesn't prevent new instances through reflection or deserialialization. To me, it doesn't make sense to use a class for a singleton anymore; too much tedious work. Just use an enum. Might actually write a guide on this
-
Singleton JFrame not appearing on script start
This is why I always recommend using enum for singletons. Its almost impossible to mess up a singleton using an enum. Glad to hear you got it working
-
Singleton JFrame not appearing on script start
It would be extremely helpful if I saw the entire singleton class. Im going based off assumpsions right now cause you're leaving out important info, such as if the field is already initialized, or if you're replacing the singleton instance by accident (make the field final). You should NOT be replacing the object in the field AT ANY TIME. You need to call `getInstance()` in your Runnable as well. Not sure why you took that out; you meed to make sure ALL swing code executes on the EDT. That littl3 change could be contributing to the problem..
-
Singleton JFrame not appearing on script start
So your Swing code looks fine. But after taking a second look at your singleton design, you never lazily initialize your singleton in the getInstance() method. This makes me assume you already have an instance created: class Single { private static Single SINGLE = new Single(); public Single() { instance = this; } public static Single getInstance() { return SINGLE; } } The problem with this design is that you instantiate the object in the field variable, then replace that object immediately after. Check this out: public Single() { System.out.println(this == SINGLE); //prints false SINGLE = this; } This could have been avoided by ensuring the field was final. Try removing instance = this
-
Singleton JFrame not appearing on script start
Please show your initComponents() method; I was hoping to see your actual Swing code, make sure everything is fine. Also, Im no fan of singletons. But if you're gonna have one, use an enum for it. As for the lambdas, they work for functional interfaces (interfaces with only 1 method). Instead of creating an anonymous class, specify an identifier for each parameter of the method (or use () if there is no parameters), then point to a statement block using ->: EventQueue.invokeAndWait(() -> { }); If your lambda only has 1 statement, you can omit the { }. If you had an enum, you would only need 1 statement: enum FrameSingleton { FRAME; //define your frame's behavior and state } It'll instantiate as soon as you refer to the enum. You would be able to do EventQueue.invokeAndWait(() -> FRAME.setVisible(true));
-
Singleton JFrame not appearing on script start
invokeLater posts your code to the Event Queue to be executed on the Event Dispatch Thread. When it will be executed is unknown. To ensure the calling thread waits until the Event Dispatch Thread has finished executing your Swing code, use invokeAndWait. Although, I can't promise this will fix it, seeing how you only show a small portion of your code.. Also, I heard OSBot now has support for Java 8. I suggest using a lambda to pass in the run() method
-
Al-Kharid MoltenGlassMaker & IronSmelter
Feel free to message me for programming advice at any time
-
Al-Kharid MoltenGlassMaker & IronSmelter
Curious as to why you didn't use an else statement rather than if(smeltSelect != null) { } if(smeltSelect == null) { } Something you could do is encapsulate each state behavior within the actual state: class MoltenGlasser extends Script { private State state; public int onLoop() throws InterruptedException { getState().process(this); return 500; } private State getState() { //... } } enum State { SMELT { @Override public void performTask(MoltenGlasser script) { script.log("Smelting"); script.cameraFix(); Entity furnace = script.objects.closest(...); //... } }, BANK { //... }; public void performTask(MoltenGlasser script) {} } This will keep your onLoop method nice and clean, and separate the logic of each state into it's own method. Also, no need to switch between cases anymore! Thanks for posting this! Every script snippit helps familiarize me with the API; much appreciated man!
-
Which IDE do you use (the most)?
Title says it all! Please use the poll
-
Canvas Help
You want getLocationOnScreen(). getBounds() returns the locatiom of the component relative to it's container, not your screen
-
Canvas Help
Please show your code so it can be identified easier, more preferrably, a MCVE
-
I'm back! (temporarily)
Hey! I've been working on some independent projects recently, so I haven't been able to be part of the community. I finally have some free time, so expect more guides and info For those wanting to contact with me during these "independent" stages, feel free to add me on skype! sincerely.vince I've mentioned before, I'm not a botter (or even a bot scripter), but I'm very experience in terms of computer science, so let me know if you wanna expand you programming knowledge!
-
2 Questions
Because they're bots who should do things for you; I find that to be a good reason to assume
-
Documentation could be a bit better
That's the problem; I'm not familiar, which is why I asked for this. It would help out new people quite a bit as well, since they can quickly view the API and get an idea of what they're going to do. I'll keep that assumpsion for now on; thanks for the heads up
-
Documentation could be a bit better
Well it's convention (similar to good identifier names). APIs should never force the client to assume things about it. Any well written documentation states these specifications. "returns null otherwise" or SOMETHING would be useful. It could return an empty array (which is actually recommended) for all I know
-
Documentation could be a bit better
It should mention that in the document's return clause /: And thanks for the information, especially about the bank booths! But I have a lot of questions.. Asking them all in a single thread would be overwhelming, and creating a bunch of new threads would clutter up the question area. I was just hoping someone, on their free time, might be able to polish up the documentation a bit
-
Documentation could be a bit better
I've seen waaaay worse when it comes to documentation, so I'm not saying it could be better based on comparisons. Since I can't run scripts and test functions (no old school RuneScape account), I'm attempting to write scripts using what I can scrape from the documentations. I have quite a few questions about some functions that can really only be answered through testing or documentation, for example: Bank#open() - "Searches for the best bank, based on type and distance of player" I'm assuming this searches for a bank within view. Of course, this is just an educated guess; I would have to test it to make sure. Maybe have something like "Searches for the best bank within sight, based on type and distance of player. Does nothing if no banks are in sight." Bank#getItems() - "Gets the array of items stored in this container" What's the container? The bank or a tab? If I call this method without the bank being open, what will happen? ______________________________________________________ It'll help out quite a bit, seeing how there's no test server. I'm sure it's the last thing you guys are worried about, but it's something that could definitely be improved. Thanks for taking the time to read this
-
npcs.interact question
If they're looking for more devs, I'd be happy to help; not sure how one would apply
-
Re-Introdcution.
Post-hardcore? Mind naming a few bands? I used to listen to quite a few bands that went by that genre, but now I rarely hear about it. Could just be due to most of my friends listening to rap and what not I'm mostly a progressive metal kind of guy now, although I listen to a lot of disco and pop, including Michael Jackson (one of my favorites). My collection of music is very diverse
-
Script isnt working correctly
EDIT: Forgot you mentioned there was a problem; my bad. While I look for it, wrap you code in proper code tags to format it, then read what I have below. Does the fill() method get called? As in, is the condition that needs to be true for fill() to execute returning true? Where EXACTLY is the problem? You rarely use String literals. Instead, you create a new StringBuilder for every String you create, even if only appending a single String. Yes, StringBuilders are efficient when needing to concat a ton of Strings, possibly within some kind of loop. But the way you're using them is actually waaaay more costly. You aren't taking advantage of the String pool, which can save you quite a bit of memory, you're creating a bunch of new StringBuilder objects (taking up quite a bit a memory, seeing hoe they contain a String themselves), and performing an un-needed method call (since you could instead just declarw the String you want in StringBuilder's constructor). String literals are your friend. Please do not use a StringBuilder every time you want a String; use a String literal instead. This will first check to see if the String you want already exists in something called a String Pool. If it does, it'll use the pre-existing value, saving you memory. This is a functionality you can only get by using String Literals. If the string doesn't already exist, a new String will be created and added to the pool. This is referred to as "interning", which can be performed manually, although should only be used in special cases. Removing those un-needed StringBuilders will save you some memory. Removing the append and toString methods will save you some processing time
-
Practical questions about R (the programming language)
Useful? Yes, in terms of data analyzing Valuable? Could easily be replaced, although I personally find it pretty useful Fun to use? Define "fun". It's more of a "get to your goal" kind of language. It allows you to quickly generate graphs based on statistics and probability Easy to learn? Compared to languages like C++ or Rust, yes. No need to worry about pointers or manually deallocating memory, allowing you to focus more on your real goal.
-
How to start?
Did you configure your project's build path to include the jar containing the library?
-
yoyoyo
Then you might be interested in Udemy aswell You can use the filter to search for free courses. You're gonna want to check occasionally to see if they've added any new courses I'll try my best! Will definitely do. Thanks for all the support you've given so far, it means a lot Hey! How's it goin? Thanks a ton man, I really appreciate the hospitality. Let me know if there's anything I could possibly help with!