Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Move to next item in array (https://forums.graalonline.com/forums/showthread.php?t=134259960)

sssssssssss 07-26-2010 10:55 PM

Move to next item in array
 
Probably a really simple answer that I'm over looking, but if you have an array

dumbarray = {1,2,3,4,5}
and you set it to 1 onCreated(),
what would you move to move it to 2?

Im using it with a time script to do days, and I prefer to do it this way since i have hours resetting at 24. Was simply going to tell the serverr.var to move when it resets.

DrakilorP2P 07-26-2010 11:03 PM

Quote:

Originally Posted by sssssssssss (Post 1589728)
Probably a really simple answer that I'm over looking, but if you have an array

dumbarray = {1,2,3,4,5}
and you set it to 1 onCreated(),
what would you move to move it to 2?

Im using it with a time script to do days, and I prefer to do it this way since i have hours resetting at 24. Was simply going to tell the serverr.var to move when it resets.

What do you mean by "set it to 1"? Do you mean you have an index variable into the array that is set to 1?
If that's the case I suppose you just increment the index variable?

Maybe you should post some code and show what you're actually doing?

fowlplay4 07-26-2010 11:04 PM

I don't understand your question but maybe this will help.

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
temp.dumbarray = {12345};
  
swapElement(temp.dumbarray.link(), 04);
  echo(
temp.dumbarray[0]); // echos 5
}

function 
swapElement(temp.arrab) {
  
temp.old temp.arr[b];
  
temp.arr[b] = temp.arr[a];
  
temp.arr[a] = temp.old;



sssssssssss 07-26-2010 11:15 PM

PHP Code:

function onCreated()
{
  
this.dayarray = {"Sunday""Monday""Tuesday""Wednesday",
    
"Thursday""Friday""Saturday"};
  
serverr.day this.dayarray[0];
  
onTimeout();


so on the getgo im making it sunday, then on the timeout

PHP Code:

function onTimeout()
{
  if (
serverr.time.hour == 24)
  { 
    
serverr.time.hour 0;
    
serverr.day this.dayarray[+1];
  }
}
    
  } 

when it resets the time back to midnight, i want it to change the day, obviously,+1 doesnt work like that. xD

Just want the array to move to the next one, even if ithe next one is [0] even if coming from [6].

Crow 07-26-2010 11:22 PM

PHP Code:

this.= { 1234};
this.aElement 0;
this.output this.a[this.aElement];

function 
NextElement() {
  
this.aElement = (this.aElement 1) % this.a.size();
  
this.output this.a[this.aElement];



DrakilorP2P 07-26-2010 11:27 PM

One-liner and without extra variables:

PHP Code:

serverr.day this.dayarray[(this.dayarray.index(serverr.day) + 1) % this.dayarray.size()]; 

Assumes that serverr.day is a valid value.

sssssssssss 07-26-2010 11:28 PM

Quote:

Originally Posted by Crow (Post 1589736)
PHP Code:

this.= { 1234};
this.aElement 0;
this.output this.a[this.aElement];

function 
NextElement() {
  
this.aElement = (this.aElement 1) % this.a.size();
  
this.output this.a[this.aElement];



How would you do that with serverr.var being the actual day set though? I think I know, but I'm going to play dumb so I can learn and not screw anything up. It needs to be a serverr.var for the day, so all people have it read, as this may change again later for dev Armageddon reasons. :P

Quote:

Originally Posted by DrakilorP2P (Post 1589738)
One-liner and without extra variables:

PHP Code:

serverr.day this.dayarray[(this.dayarray.index(serverr.day) + 1) % this.dayarray.size()]; 

Assumes that serverr.day is a valid value.

so if onCreated i declare it array[0] and use that will it be ok?

Crow 07-26-2010 11:58 PM

Quote:

Originally Posted by DrakilorP2P (Post 1589738)
One-liner and without extra variables:

PHP Code:

serverr.day this.dayarray[(this.dayarray.index(serverr.day) + 1) % this.dayarray.size()]; 

Assumes that serverr.day is a valid value.

Should avoid that. Unnecessary CPU cycles. Calling array.index() can be very slow when the array is big.


Quote:

Originally Posted by sssssssssss (Post 1589739)
How would you do that with serverr.var being the actual day set though? I think I know, but I'm going to play dumb so I can learn and not screw anything up. It needs to be a serverr.var for the day, so all people have it read, as this may change again later for dev Armageddon reasons. :P

Use a serverr.var of your choice instead of this.output. this.a will be your array, obviously. Also, the whole thing is just an example. You don't have to create an extra function for that stuff.

sssssssssss 07-27-2010 12:19 AM

Quote:

Originally Posted by DrakilorP2P (Post 1589738)
One-liner and without extra variables:

PHP Code:

serverr.day this.dayarray[(this.dayarray.index(serverr.day) + 1) % this.dayarray.size()]; 

Assumes that serverr.day is a valid value.

Quote:

Originally Posted by Crow (Post 1589736)
PHP Code:

this.= { 1234};
this.aElement 0;
this.output this.a[this.aElement];

function 
NextElement() {
  
this.aElement = (this.aElement 1) % this.a.size();
  
this.output this.a[this.aElement];



With the code I posted, I'm not following how to incorporate this into it. Im not asking for an exact example with what I have. If that happens though, please explain.

fowlplay4 07-27-2010 12:23 AM

Just store day as a 0 to 6 value, and have your script convert that to a day (Monday, etc.) on the client.

Scripted Time in it's simplest form:

PHP Code:

function onCreated() {
  
setTimer(60);
}

function 
onTimeout() {
  
incrementTime();
  
setTimer(60);
}

function 
incrementTime() {
  
serverr.time_minute++;
  if (
serverr.time_minute == 60) {
    
serverr.time_minute 0;   
    
serverr.time_hour++;
    if (
serverr.time_hour == 24) {
      
serverr.time_hour 0;
      
serverr.time_day++;
      if (
serverr.time_day == 7) {
        
serverr.time_day 0;
      }
    }
  }


PHP Code:

//#CLIENTSIDE

function getCurrentDay() {
  return {
"Sunday""Monday""Tuesday""Wednesday""Thursday""Friday""Saturday"}[serverr.time_day];


It doesn't look all that pretty but whatever.

xAndrewx 07-27-2010 12:41 AM

Why don't you base it on timevar2?

http://forums.graalonline.com/forums...hp?t=134258550

Or if you want the serverlister time (time on the Graal taskbar)

HTML Code:

Serverlist_TaskBar_Label.text

Crow 07-27-2010 01:07 AM

Quote:

Originally Posted by xAndrewx (Post 1589748)
Or if you want the serverlister time (time on the Graal taskbar)

I don't think anybody wants that :\ Unfortunately, it represents timevar2, and is way off. And Stefan doesn't seem to care either. ****ing annoying.


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

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