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-22-2012, 11:54 PM
Stowen Stowen is offline
Graalian since '01
Join Date: Sep 2005
Location: Massachusets, USA
Posts: 156
Stowen will become famous soon enough
Send a message via AIM to Stowen Send a message via MSN to Stowen
Trying to make a Timer

Hello. I'm trying to make a countdown timer, but it doesn't seem to be working. I'm also not sure of the best way to go about it.

Here is what I have so far:

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
this.timer == 15;
  
this.chat "Countdown";
}

function 
onPlayerChats() {
  if (
player.chat == "/count") {
    
this.timer == 15;
    
onTimeOut();
  }
}

function 
onTimeOut() {
  
this.timer 1;
  
this.chat this.timer;
  
setTimer(1);

Reply With Quote
  #2  
Old 06-23-2012, 12:02 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
You have a double equals sign (which are for comparing values) in your timer assignments.

Reducing the timer should also either be this.timer --; or this.timer -= 1;
Reply With Quote
  #3  
Old 06-23-2012, 12:05 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
In your onCreated() function, you are using the equality operator (==) to assign a value. This will not work. When assigning values to variables, use a single equality sign. This also applies to your onPlayerChats() function. Also, since you're setting this.timer (you might want to change the name as well, I bet that's reserved) in onPlayerChats(), it seems a bit redundant to also do that in onCreated().

Next, you'll want to decrement a variable by using either of these two methods:
PHP Code:
this.var--;
this.var -= 1
What you're doing in your timeout will not work. Finally, you should probably check inside your timeout if the countdown has reached zero and, if it has, do not continue the timeout.
__________________
Reply With Quote
  #4  
Old 06-23-2012, 12:12 AM
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
PHP Code:
//#CLIENTSIDE
function onCreated() {
  
// I'd be wary of using a variable named this.timer. This.timer might be reserved for actual timeouts
  
  // Initiate a new variable that logs the current time
  // We will later use this to keep track of the countdown
  // via offsetting it. If this.countdowntime > timevar2, then assume it is counting down
  
this.countdowntime timevar2;
}

function 
onPlayerChats() {
  
// Call the function to start the countdown, let it know you want it to be 15 seconds
  
if (player.chat == "/count"Countdown(15);
}

function 
Countdown(t) {
  
// Take timevar2 as a reference point and add the time(t) provided to it. This will let
  // the script know there is now time + t amount of time for the countdown
  
this.countdowntime timevar2 t;

  
// As long as timevar2 is less than this.countdowntime, then there is a countdown occuring
  // Use while to create a loop(for updating). This is similar to a timeout, as it will
  // continue to execute the script as long as the statement is true
  
while (timevar2 this.countdowntime) {
    
// Do some basic math to find the difference in time(the countdown)
    // Also round it with int(x + .5) or else you'll get large floating values like 12.23463452342345356463
    
this.chat int(this.countdowntime timevar2 .5);

    
sleep(.5); // No need to update the loop more frequently than this since we're providing decrements in seconds
  
}
 
  
this.chat "Countdown complete!";

Reply With Quote
  #5  
Old 06-23-2012, 02:49 AM
Stowen Stowen is offline
Graalian since '01
Join Date: Sep 2005
Location: Massachusets, USA
Posts: 156
Stowen will become famous soon enough
Send a message via AIM to Stowen Send a message via MSN to Stowen
Thank you guys!
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:39 PM.


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