SRL Archive - FAQ

Threads


edfromhumanresources

2011-04-16 17:16:08

How can one define and run threads in simba?

i luffs yeww

2011-04-16 17:27:54

One cannot.

edfromhumanresources

2011-04-16 17:30:37

Is this some sort of technical limitation or just no one has been arsed to implement it yet?

i luffs yeww

2011-04-16 17:32:02

It's because of our interpreter afaik. But I also don't know much, so I'll stop spamming.

I think threads are possible in Pascal, which is what Simba is made in, so it could be possible, but I don't know (because Pascal has pointers, but we have no pointers in PS, so I dunno why we can't).

Sex

2011-04-16 17:48:50

There are internal threads but users cannot create there own. You can use extensions though maybe?

Wizzup?

2011-04-17 04:35:37

From: edfromhumanresources
Is this some sort of technical limitation or just no one has been arsed to implement it yet?


Obviously there's no actual ``technical'' limitation, as it would theoretically be possible. However, the interpreters in Simba don't support threading. And it's not easy to ``hack'' threading it. There are some other threading related hacks you can do though. Did you want another thread for performance or logic? (Generally I wouldn't recommend doing real performance-related work in Simba's interpreter…)

And if you don't want to use SRL; but say, only Simba's main functions. (Find colors, manipulate mouse, keyboard) you could also write your program in Free Pascal. Simba is written in this and you can easily extend your program with Simba units. Free Pascal supports threads and the Simba library AFAIK is thread safe. Eventually other languages will be supported.

edfromhumanresources

2011-04-19 11:59:27

From: Wizzup?
Obviously there's no actual ``technical'' limitation, as it would theoretically be possible. However, the interpreters in Simba don't support threading. And it's not easy to ``hack'' threading it. There are some other threading related hacks you can do though. Did you want another thread for performance or logic? (Generally I wouldn't recommend doing real performance-related work in Simba's interpreter…)

And if you don't want to use SRL; but say, only Simba's main functions. (Find colors, manipulate mouse, keyboard) you could also write your program in Free Pascal. Simba is written in this and you can easily extend your program with Simba units. Free Pascal supports threads and the Simba library AFAIK is thread safe. Eventually other languages will be supported.


I just feel it would be highly beneficial for scripts that require fast response to multiple sources of change to split various tasks into threads and use semaphore/locking for flow control. I also think they would improve code readability if used well.

It's definetly something I'll look into when I have time.

Richard

2011-04-19 13:43:17

I seem to remember somewhere that it's possible to implement pseudo threading, I think. It would be very useful to have it, so we could have message listeners to read server messages, mouse listeners so it could interact well with a paint. Or events from a server? Would be incredible effective for scripting runescape, as multiple things happen at once.

But yeah, I think TTimers can function as some form of pseudo multi-threading, don't quote me on that.

footballjds

2011-04-19 13:53:26

From: edfromhumanresources
I just feel it would be highly beneficial for scripts that require fast response to multiple sources of change to split various tasks into threads and use semaphore/locking for flow control. I also think they would improve code readability if used well.

It's definetly something I'll look into when I have time.


then use Java.

i luffs yeww

2011-04-19 13:59:57

Yes, you can do some stuff with TTimers, but it's not the most reliable or effective method, iirc.

I've been thinking about threads a lot lately and I still don't know if I think we should use them if we can. It just seems like it would lead to many bad scenarios in which people may not be prepared for and that's not what we want.

But on the other hand, tools for advanced scripters are good, so maybe. I dunno.

Also, don't use Java.

footballjds

2011-04-19 14:08:31

From: i luffs yeww
Also, don't use Java.


you're not going to get true multithreading with simba/scar.
EVER

i luffs yeww

2011-04-19 14:13:47

From: footballjds
you're not going to get true multithreading with simba/scar.
EVER


That's not true. With a changed interpreter and language we could. According to Wizzup?, Simba/MML can handle threads, so if we used a language that could support threads, we could use threads with Simba.

The reason we can't use threads now is because we're using PascalScript (same reason why SCAR won't support threads any time soon).

Python will be first, and I don't know if anyone will want to use threads with that, but another language may.

Richard

2011-04-20 05:40:52

From: footballjds
you're not going to get true multithreading with simba/scar.
EVER


Wizzup made a comment, I think, about adding more languages to Simba in future. It currently uses PascalScript which doesn't support true multithreading, but pascal variants like FreePascal support multithreading if I'm not mistaken.

EDIT: And java wouldn't be a half bad idea, considering it's what runescape is made with…

Wizzup?

2011-04-20 05:46:13

From: footballjds
you're not going to get true multithreading with simba/scar.
EVER


I've been thinking for five minutes or so to express how dumb I find this post, but without trying to offend you. I just ended up with this. I can't think of anything more suitable.

Richard, seeing SRL doesn't do client hacking I don't see the advantage of making SRL ``just another java bot''. Java isn't a programming language fit for scripting either.

Iamadam

2011-04-20 06:12:32

@the general Java hate: …. A wild rage baby appears!
[rage]Java is incredible and far superior to PS in almost every way.
There, I said it.[/rage]

No offense meant to anyone, but just because Java is often associated with ignorant fools (i.e. powerbot.org) doesn't mean it is a bad language. It is fast, reliable and _excellent_ for runescape scripting if properly implemented.


Now on topic: No, TTimers don't work for 'multithreading' in PS. The 'onTimer' event is never called.

i luffs yeww

2011-04-20 06:45:29

Well PS is an awful thing to compare any language to. :p I'd say most languages are better than PS (well.. there are a plethora of languages, so maybe not MOST, but I hope you know what I'm getting at.. it's 4/20 btw).

I have a hard time accepting Java just because of how awful it runs. I don't even have Java installed because I hate dealing with it.

And no unsigned types. :<

Wizzup?

2011-04-20 07:40:13

From: Iamadam
@the general Java hate: …. A wild rage baby appears!
[rage]Java is incredible and far superior to PS in almost every way.
There, I said it.[/rage]

No offense meant to anyone, but just because Java is often associated with ignorant fools (i.e. powerbot.org) doesn't mean it is a bad language. It is fast, reliable and _excellent_ for runescape scripting if properly implemented.


Now on topic: No, TTimers don't work for 'multithreading' in PS. The 'onTimer' event is never called.


But it's not a scripting language, so why would you use it for scripting? Scriping is really just glueing together Simba calls and enforce order on them with logic.

Yeah, Java is generally fast. But damn, it starts SLOWLY. I think even PS starts faster.

Iamadam

2011-04-20 07:57:10

Its great for scripting because it can be as simple as piecing together a bunch of pre-written methods - but expanded to complex multithreaded object oriented scripts.
It has all the ease of PS, with a bunch of extra functionality.

As for the start up time, it can be slow - but when huge libraries (like SRL) are used in PS, it is just as slow to compile & run.

Nothing wrong with PS, and it works fine for what we use it for. But at the same time, there's a real ignorance in this community about what Java is and what its capabilities are (I don't mean you Wizzup? or anyone else in this thread). I understand that it has been given a bad name by a lot of cheating sites around the place (poorly designed bots make it appear far slower than it is, and poorly written scripts combined with the general stupidity of most on Java based bot sites probably suck appeal from it).

I just gotta advocate for Java because its the reason I got into programming, and I know people who can use it to do amazing things :)

Wizzup?

2011-04-20 08:28:46

From: Iamadam
Its great for scripting because it can be as simple as piecing together a bunch of pre-written methods - but expanded to complex multithreaded object oriented scripts.
It has all the ease of PS, with a bunch of extra functionality.

As for the start up time, it can be slow - but when huge libraries (like SRL) are used in PS, it is just as slow to compile & run.

Nothing wrong with PS, and it works fine for what we use it for. But at the same time, there's a real ignorance in this community about what Java is and what its capabilities are (I don't mean you Wizzup? or anyone else in this thread). I understand that it has been given a bad name by a lot of cheating sites around the place (poorly designed bots make it appear far slower than it is, and poorly written scripts combined with the general stupidity of most on Java based bot sites probably suck appeal from it).

I just gotta advocate for Java because its the reason I got into programming, and I know people who can use it to do amazing things :)


I don't dislike Java because of all the Java bots around, I dislike it because I dislike the language. I've taught it for two years at my university - and I still don't like it. I'm not saying it has no applications, I just don't see how it fits as a language to ``control'' Simba functionality. It's statically typed, this is huge disadvantage if you want use it as scripting language. (Yes, PS is statically typed as well) It's also quite verbose, and the functionality to map or use lambdas is lacking.

footballjds

2011-04-20 10:02:34

From: i luffs yeww
That's not true. With a changed interpreter and language we could. According to Wizzup?, Simba/MML can handle threads, so if we used a language that could support threads, we could use threads with Simba.

The reason we can't use threads now is because we're using PascalScript (same reason why SCAR won't support threads any time soon).

Python will be first, and I don't know if anyone will want to use threads with that, but another language may.


From: Wizzup?
I've been thinking for five minutes or so to express how dumb I find this post, but without trying to offend you. I just ended up with this. I can't think of anything more suitable.

Richard, seeing SRL doesn't do client hacking I don't see the advantage of making SRL ``just another java bot''. Java isn't a programming language fit for scripting either.


I'll have to remember not to write posts that without double checking them or else i'll get my ass handed to me… :o :o :o :o :o :o
For the sake of trying to not look like a complete fool:
obviously if you changed the compiler(simba) to support another language that utilizes multi-threading you could get multi-threading… This however is what i mistakingly didn't state…
I meant that the language we currently use(not the compiler, i simply associated the two… :duh: ) is holding us back. My mistake almighty SRLer's

Wizzup?

2011-04-20 10:19:06

From: footballjds
I meant that the language we currently use(not the compiler, i simply associated the two… :duh: ) is holding us back. My mistake almighty SRLer's


That's true. If you by language mean PascalScript. :)

footballjds

2011-04-20 10:20:09

From: Wizzup?
That's true. If you by language mean PascalScript. :)


Indeed.
:o

edfromhumanresources

2011-04-20 10:29:15

I'm mainly a java programmer myself and while its an awesome language you would need to use jni or jna to get half of simbas core functions as methods and I've run into some pretty disastrous bugs with both, such as garbage collecting jna callback methods crashing the vm with no solution.

There are many benfits to java such as full oo, decent speed with jit and threads etc, but you would find your script that used to be in one file for download, easy to learn from, and quickly modify to others needs turn into either multiple source files or a bytecode blob. The most likely scenario is people would just upload .jars which doesn't encourage code sharing and in turn community.

If you want to script use a scripting language.

All my opinion of course.

nielsie95

2011-04-20 11:07:40

Well, just as we have ThreadSafeCall, I'm sure there's something you can come up with to sort of support threads. Interacting between them is probably the hardest part.

i luffs yeww

2011-04-20 15:06:10

From: Iamadam
words


I, quite honestly, just really think that Java has a lot of silly "features" and non-features that don't make an awful lot of sense. I don't like garbage collection (at at least not Java's, in practice with most Java applications), I don't like the JVM, and it's just a nuisance to have running, imo. And not only this, but I see no reason to use it over any other language (if there was no C or C++, but Java somehow existed as it does today, then maybe it would be a decent language choice, but that's not the case). I know my arguments aren't very technical, but whatever. I'll look more into Java's internals later if I can.

From: Wizzup?
It's statically typed, this is huge disadvantage if you want use it as scripting language.


I don't understand that at all. Why would dynamic typing be a good choice, ever? I don't think the speed loss, increased confusion, and chances that things will work together being lowered are at a low enough cost that the pros win (pros don't outweigh the cons for dynamically typed languages).

Wizzup?

2011-04-20 15:32:34

From: i luffs yeww
I, quite honestly, just really think that Java has a lot of silly "features" and non-features that don't make an awful lot of sense. I don't like garbage collection (at at least not Java's, in practice with most Java applications), I don't like the JVM, and it's just a nuisance to have running, imo. And not only this, but I see no reason to use it over any other language (if there was no C or C++, but Java somehow existed as it does today, then maybe it would be a decent language choice, but that's not the case). I know my arguments aren't very technical, but whatever. I'll look more into Java's internals later if I can.



I don't understand that at all. Why would dynamic typing be a good choice, ever? I don't think the speed loss, increased confusion, and chances that things will work together being lowered are at a low enough cost that the pros win (pros don't outweigh the cons for dynamically typed languages).


Dynamic languages:
  • Eval, map, etc
  • Don't check for runtime errors on compilation (this is a good thing)
  • Duck typing, code reuse. Code is often a lot smaller, more readable.
  • lambda calculus
  • Pickling, marshalling, etc.

Python is dynamic, PHP is dynamic, Ruby is dynamic, etc. These are all widespread languages. They are used for more things than just web programming, for example.

Simply think of the advantages you think Python offers, then see how many of them only apply to dynamically typed languages. Like I said, the speed improvement for static languages is IRRELEVANT for our purposes…

Iamadam

2011-04-20 19:35:53

When I was talking about Java, I didn't mean to push it as a replacement for PS. Was just defending the fact that it's great :P

Also, garbage collection is amazing. "Memory leaks? What are they??"

Wizzup?

2011-04-21 03:47:48

From: Iamadam
When I was talking about Java, I didn't mean to push it as a replacement for PS. Was just defending the fact that it's great :P

Also, garbage collection is amazing. "Memory leaks? What are they??"


Or, to put it differently: Efficient memory management? What is that? Let's just create a lot of classes instead of plain datatypes because we really need them! What is realloc? Who ever uses that? ;)

nielsie95

2011-04-21 04:25:40

From: Wizzup?
Dynamic languages:
  • Eval, map, etc
  • Don't check for runtime errors on compilation (this is a good thing)
  • Duck typing, code reuse. Code is often a lot smaller, more readable.
  • lambda calculus
  • Pickling, marshalling, etc.


Maps, serialization, code reuse and lambda calculus can just as easy be implemented in statically typed languages (I believe the latest Delphi supports those). The error checking is one of the major downsides in dynamic languages (why would it be a good thing?). Duck typing can also be implemented in a statically typed language (take a look at Scala, for example).

Eval and dynamic types are the pro's I can think of (and they are big pro's, but only if you need them), although eval could be considered bad practice. They are nice to have, because they make things easier for the (lazy) programmer.

Personally, I don't see why a dynamically typed language would be so much better than a statically typed language for RS scripts. I think that a statically typed language would be better to keep consistency in SRL and scripts (know how to use a function, just by looking at its header).

i luffs yeww

2011-04-22 16:50:38

From: nielsie95
dat quote.


I agree with most of this, but I don't really see any reason to use eval. As far as I can tell, there's never a situation in which you should use eval() over a different method (like print, except if you want to be really lazy and be dumb with errors and all that, but whatever).

Also, I still don't see why duck typing is good. :/ I'd much rather people have to type "int" and catch errors of something bad happens than just randomly throw variables everywhere without ever saying what type they are. I can understand that 99% of the time, but it also will indubitably cause confusion in big projects if people start using vars like nothing bad can happen and they can do whatever they want with them.

And I'm pretty certain you, Wizzup?, won't be making the includes or working on Python projects for SRL (I don't expect you to; you're busy and do work on other stuff, which is very important), so it is something that will come up (errors with variables/types), and is important to know that there will be bad practice, which is why a statically typed language > dynamically typed language (in all cases, imo, but especially here).