Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Repeating chat? (https://forums.graalonline.com/forums/showthread.php?t=134266593)

Fysez 06-07-2012 04:34 AM

Repeating chat?
 
I thought maybe this would work
PHP Code:

function onCreated() {
this.chat "Message1";
if (
this.chat "Message1") {
sleep(3);
this.chat "Message2";
} else if (
this.chat "Message2") {
sleep(3);
this.chat "Message1";
}


This only makes the NPC say "Message1" , "Message2". And there it stops.
How can this be fixed up?

fowlplay4 06-07-2012 04:37 AM

You don't need an if statement, just use a timeout.

PHP Code:

function onCreated() {
  
onTimeout();
}

function 
onTimeout() {
  
this.chat "Message1";
  
sleep(3);
  
this.chat "Message2";
  
setTimer(3);


I'm pretty sure you've been told this before but use 2 equal signs instead of one when you're comparing values. I.e. if (this.variable == 1) { // stuff

Fysez 06-07-2012 04:41 AM

Quote:

Originally Posted by fowlplay4 (Post 1696644)
You don't need an if statement, just use a timeout.

PHP Code:

function onCreated() {
  
onTimeout();
}

function 
onTimeout() {
  
this.chat "Message1";
  
sleep(3);
  
this.chat "Message2";
  
setTimer(3);


I'm pretty sure you've been told this before but use 2 equal signs instead of one in an in if statement. I.e. if (this.variable == 1) { // stuff

Oh, Duh. Wow, Can't believe I didn't think of that x.x Thanks=P
And yeah I have, But it works either way:P
Thanks again

Crow 06-07-2012 08:40 AM

Quote:

Originally Posted by Fysez (Post 1696645)
But it works either way:P

No, it does not. Just don't do it. Using a single equality sign makes this an assignment. You do not want that.

Tricxta 06-07-2012 09:09 AM

Quote:

Originally Posted by Crow (Post 1696658)
No, it does not. Just don't do it. Using a single equality sign makes this an assignment. You do not want that.

True that, especially in proper languages like java where you can do things like while ((aString = br.readLine()) != null){...

It's best to practice proper coding form at all times or you set yourself up with nasty habits which catch up with you later on x_x

Hezzy002 06-07-2012 01:28 PM

lmao quote of the year, "In proper languages like Java..."

Emera 06-07-2012 01:36 PM

Quote:

Originally Posted by Hezzy002 (Post 1696666)
lmao quote of the year, "In proper languages like Java..."

It's not as bad as me assuming you coded a chat room in VB just because of the icon of the window ;)

cbk1994 06-07-2012 04:57 PM

Quote:

Originally Posted by Hezzy002 (Post 1696666)
lmao quote of the year, "In proper languages like Java..."

You may not think Java is a good language, but how is it not a proper one? Are all languages you dislike improper? :oo:

Crono 06-07-2012 05:41 PM

Quote:

Originally Posted by Hezzy002 (Post 1696666)
lmao quote of the year, "In proper languages like Java..."

ya, we all know erlang is the way to go!

Hezzy002 06-07-2012 07:27 PM

Quote:

Originally Posted by cbk1994 (Post 1696671)
You may not think Java is a good language, but how is it not a proper one? Are all languages you dislike improper? :oo:

I dunno, define proper. Isn't proper just an opinion? Opinion of the masses isn't too supportive of Java.

cbk1994 06-07-2012 07:32 PM

Quote:

Originally Posted by Hezzy002 (Post 1696676)
I dunno, define proper. Isn't proper just an opinion? Opinion of the masses isn't too supportive of Java.

Don't know what masses you're polling, Java is still one of the most widely-used programming languages. It certainly has faults, but I wouldn't "lmao" at someone saying that Java is a proper language, especially when they're comparing it to GScript.

DustyPorViva 06-07-2012 07:47 PM

You may also be interested in making this a bit more flexible using arrays.
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
// Create an array with a value for each message desired
  
this.messages = {
    
"message one!",
    
"message two!",
    
"message three!",
    
"message four!"
  
};

  
// Initiate the timeout loop
  
onTimeout();
}

function 
onTimeout() {
  
// Loop through each item in this.messages array
  // for (var : array) will loop through 'array' and execute the code for each value
  
for (temp.this.messages) {
    
player.chat temp.i;
    
sleep(3);
  }
  
// Restart the loop
  
setTimer(3);


With such an approach all you'd have to do is add more messages to the array to create a larger loop.

Hezzy002 06-07-2012 08:02 PM

Quote:

Originally Posted by cbk1994 (Post 1696679)
Don't know what masses you're polling, Java is still one of the most widely-used programming languages. It certainly has faults, but I wouldn't "lmao" at someone saying that Java is a proper language, especially when they're comparing it to GScript.

Perl is still widely used, mate. Doesn't mean the reasonable people like it.

EDIT: Not really saying that I have any huge issues with Java. The biggest qualms I have are in regards to the GC (Something I only want to see in an embedded scripting language), lack of operator overloading (Something useful that helps continuity), and the fact that everything requires a wrapper class (Hardcore OO is counter productive to a purely functional program).

Most of my opinions are also heavily based on game development. The language and VM just isn't suited to it IMO. There isn't a lot of middleware for Java, low-level functionality is out the window, and even though the VM executes relatively quick because it's JIT'd, GC is a huge bottleneck. Imagine if CoD had stuttering ingame as the Java VM frantically searched through memory to try to find some available to allocate and others to free (Not multithreaded, pretty sure it's impossible to do completely asynchronously).

Also can't handle an object's memory directly (Super useful for parsing binary file formats; just pointer to file data -> struct in the same format and the header's parsed), can't even shallow copy objects automagically (memcpy would work in C).

Sure, these issues wouldn't crop up for a lot of programming projects, but they cropped up hundreds of times for me when I was trying to make a game engine in Java, and pretty much every game developer I know hates Java and JVM with a passion.

cbk1994 06-08-2012 01:53 AM

Quote:

Originally Posted by Hezzy002 (Post 1696683)
Perl is still widely used, mate. Doesn't mean the reasonable people like it.

EDIT: Not really saying that I have any huge issues with Java. The biggest qualms I have are in regards to the GC (Something I only want to see in an embedded scripting language), lack of operator overloading (Something useful that helps continuity), and the fact that everything requires a wrapper class (Hardcore OO is counter productive to a purely functional program).

Most of my opinions are also heavily based on game development. The language and VM just isn't suited to it IMO. There isn't a lot of middleware for Java, low-level functionality is out the window, and even though the VM executes relatively quick because it's JIT'd, GC is a huge bottleneck. Imagine if CoD had stuttering ingame as the Java VM frantically searched through memory to try to find some available to allocate and others to free (Not multithreaded, pretty sure it's impossible to do completely asynchronously).

Also can't handle an object's memory directly (Super useful for parsing binary file formats; just pointer to file data -> struct in the same format and the header's parsed), can't even shallow copy objects automagically (memcpy would work in C).

Sure, these issues wouldn't crop up for a lot of programming projects, but they cropped up hundreds of times for me when I was trying to make a game engine in Java, and pretty much every game developer I know hates Java and JVM with a passion.

I'm not arguing that Java is a good language, just that it is a language :). I would consider Perl a language as well, even though I read very little good about it.

salesman 06-08-2012 04:06 AM

Quote:

Originally Posted by Hezzy002 (Post 1696683)
Perl is still widely used, mate. Doesn't mean the reasonable people like it.

EDIT: Not really saying that I have any huge issues with Java. The biggest qualms I have are in regards to the GC (Something I only want to see in an embedded scripting language), lack of operator overloading (Something useful that helps continuity), and the fact that everything requires a wrapper class (Hardcore OO is counter productive to a purely functional program).

Most of my opinions are also heavily based on game development. The language and VM just isn't suited to it IMO. There isn't a lot of middleware for Java, low-level functionality is out the window, and even though the VM executes relatively quick because it's JIT'd, GC is a huge bottleneck. Imagine if CoD had stuttering ingame as the Java VM frantically searched through memory to try to find some available to allocate and others to free (Not multithreaded, pretty sure it's impossible to do completely asynchronously).

Also can't handle an object's memory directly (Super useful for parsing binary file formats; just pointer to file data -> struct in the same format and the header's parsed), can't even shallow copy objects automagically (memcpy would work in C).

Sure, these issues wouldn't crop up for a lot of programming projects, but they cropped up hundreds of times for me when I was trying to make a game engine in Java, and pretty much every game developer I know hates Java and JVM with a passion.

It is true that there's really nothing you can do once GC kicks in, but I've read several studies showing that programs with GC can often outperform direct memory management. This is particularly true for long-running processes. A good read is this article, which claims "dynamic memory management is not as fast [as direct memory mgmt] -- it's often considerably faster." It also states that between 92 and 98 percent of the time, GC merely has to bump a pointer. There was one study in particular I wanted to point out, but the link appears to be dead =(.

Also, JNI can alleviate most of the issues with low-level functionality, but if you're developing an application that requires a lot of low level processing, you shouldn't be using Java in the first place. This doesn't mean it's a bad language, it's just not what it was designed for.

You are right that Java is not ideal for game development, but if you know what you're doing, it definitely wouldn't be as big of an issue as you're making it out to be. Take a look at libGDX, for example.

Java, like any other language, has its pros and cons. A few cons being the large memory footprint (if you include the JVM) and slow startup times (loading JVM, JIT compilation, etc). A few pros being readability, the relative easiness to develop applications quickly (because it's so high-level), compatibility, JIT compilation which can perform machine-specific optimizations and even further optimizations as a result of run-time statistics gathered by the JVM.

Crow 06-08-2012 08:12 AM

Quote:

Originally Posted by Hezzy002 (Post 1696683)
Perl is still widely used, mate. Doesn't mean the reasonable people like it.

Quote:

Originally Posted by cbk1994 (Post 1696703)
I would consider Perl a language as well, even though I read very little good about it.

Now that's confusing. Even though I wouldn't consider Perl exceptionally awesome, it receives lots of praise from many people. Haven't seen much negative talk about it.

xXziroXx 06-09-2012 04:02 AM

Quote:

Originally Posted by Crow (Post 1696717)
Now that's confusing. Even though I wouldn't consider Perl exceptionally awesome, it receives lots of praise from many people. Haven't seen much negative talk about it.

What? I'm not even much of anything of a programmer outside of Graal, and even I know Perl is widely known to be considered crap.

Crow 06-09-2012 02:16 PM

Quote:

Originally Posted by xXziroXx (Post 1696765)
What? I'm not even much of anything of a programmer outside of Graal, and even I know Perl is widely known to be considered crap.

Not sure who would consider it crap, as it really isn't that bad. My weapon of choice in terms of high level scripting languages will always be either Python or Lua, but Perl is not a huge pile of **** either and is used fairly often.

salesman 06-09-2012 07:57 PM

Which Perl are you talking about?


All times are GMT +2. The time now is 01:18 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.