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 07-26-2010, 10:55 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
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.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #2  
Old 07-26-2010, 11:03 PM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
Quote:
Originally Posted by sssssssssss View Post
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?
Reply With Quote
  #3  
Old 07-26-2010, 11:04 PM
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
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;

__________________
Quote:
Reply With Quote
  #4  
Old 07-26-2010, 11:15 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
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].
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #5  
Old 07-26-2010, 11:22 PM
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
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];

Reply With Quote
  #6  
Old 07-26-2010, 11:27 PM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
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.
Reply With Quote
  #7  
Old 07-26-2010, 11:28 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
Quote:
Originally Posted by Crow View Post
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 View Post
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?
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #8  
Old 07-26-2010, 11:58 PM
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 DrakilorP2P View Post
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 View Post
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.
Reply With Quote
  #9  
Old 07-27-2010, 12:19 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
Quote:
Originally Posted by DrakilorP2P View Post
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 View Post
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.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #10  
Old 07-27-2010, 12:23 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
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.
__________________
Quote:
Reply With Quote
  #11  
Old 07-27-2010, 12:41 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
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
__________________
Reply With Quote
  #12  
Old 07-27-2010, 01:07 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 xAndrewx View Post
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.
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 12:38 AM.


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