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 just really niceTricxta is just really nice
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, 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
  #10  
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
  #11  
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
  #12  
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
  #13  
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
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 08:26 PM.


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