Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-07-2012, 04:34 AM
Fysez Fysez is offline
Banned
Join Date: Apr 2012
Posts: 89
Fysez has a little shameless behaviour in the past
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?
Reply With Quote
  #2  
Old 06-07-2012, 04:37 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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
__________________
Quote:
Reply With Quote
  #3  
Old 06-07-2012, 04:41 AM
Fysez Fysez is offline
Banned
Join Date: Apr 2012
Posts: 89
Fysez has a little shameless behaviour in the past
Quote:
Originally Posted by fowlplay4 View Post
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
Reply With Quote
  #4  
Old 06-07-2012, 08:40 AM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Fysez View Post
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.
__________________
Reply With Quote
  #5  
Old 06-07-2012, 09:09 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is a jewel in the roughTricxta is a jewel in the rough
Quote:
Originally Posted by Crow View Post
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
Reply With Quote
  #6  
Old 06-07-2012, 01:28 PM
Hezzy002 Hezzy002 is offline
Registered User
Join Date: Jul 2011
Posts: 247
Hezzy002 is a jewel in the roughHezzy002 is a jewel in the rough
lmao quote of the year, "In proper languages like Java..."
Reply With Quote
  #7  
Old 06-07-2012, 01:36 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Quote:
Originally Posted by Hezzy002 View Post
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
Reply With Quote
  #8  
Old 06-07-2012, 04:57 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Hezzy002 View Post
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?
__________________
Reply With Quote
  #9  
Old 06-07-2012, 05:41 PM
Crono Crono is offline
:pluffy:
Join Date: Feb 2002
Location: Sweden
Posts: 20,000
Crono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond repute
Quote:
Originally Posted by Hezzy002 View Post
lmao quote of the year, "In proper languages like Java..."
ya, we all know erlang is the way to go!
__________________
Reply With Quote
  #10  
Old 06-07-2012, 07:27 PM
Hezzy002 Hezzy002 is offline
Registered User
Join Date: Jul 2011
Posts: 247
Hezzy002 is a jewel in the roughHezzy002 is a jewel in the rough
Quote:
Originally Posted by cbk1994 View Post
You may not think Java is a good language, but how is it not a proper one? Are all languages you dislike improper?
I dunno, define proper. Isn't proper just an opinion? Opinion of the masses isn't too supportive of Java.
Reply With Quote
  #11  
Old 06-07-2012, 07:32 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Hezzy002 View Post
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.
__________________
Reply With Quote
  #12  
Old 06-07-2012, 07:47 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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.
Reply With Quote
  #13  
Old 06-07-2012, 08:02 PM
Hezzy002 Hezzy002 is offline
Registered User
Join Date: Jul 2011
Posts: 247
Hezzy002 is a jewel in the roughHezzy002 is a jewel in the rough
Quote:
Originally Posted by cbk1994 View Post
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.

Last edited by Hezzy002; 06-07-2012 at 09:21 PM..
Reply With Quote
  #14  
Old 06-08-2012, 01:53 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Hezzy002 View Post
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.
__________________
Reply With Quote
  #15  
Old 06-08-2012, 04:06 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
Quote:
Originally Posted by Hezzy002 View Post
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.
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:53 PM.


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