Graal Forums  

Go Back   Graal Forums > Graal V6 forums > Bug Report
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 11-21-2008, 04:41 PM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
"in" operator on returned array.

The error I've found is that if you want to use the var in array, the array needs to be a variable defined in the function itself; not a returned value from a function. ( I also highly suspect that someArray()[2] doesn't work. )

PHP Code:
function someArray() {
  return {
0,1,2,3};
}

function 
onCreated() {
  if ( 
2 in someArray() ) {
    echo(
"Works!");
  } else {
    echo(
"Doesn't work.");
  }

Reply With Quote
  #2  
Old 11-21-2008, 04:59 PM
TSAdmin TSAdmin is offline
Forum Moderator
TSAdmin's Avatar
Join Date: Aug 2006
Location: Australia
Posts: 1,980
TSAdmin is a splendid one to beholdTSAdmin is a splendid one to beholdTSAdmin is a splendid one to beholdTSAdmin is a splendid one to beholdTSAdmin is a splendid one to behold
I've also noticed this. I tried something along these lines not so long ago and I had to migrate the array to the function it was being used in or it would not work at all, which is really quite annoying, inconvenient and can be generally unclean if you want to group some different arrays in a single function to avoid having them scattered throughout the different functions they're used for.
__________________
TSAdmin (Forum Moderator)
Welcome to the Official GraalOnline Forums! Where sharing an opinion may be seen as a declaration of war!
------------------------
· User Agreement · Code of Conduct · Forum Rules ·
· Graal Support · Administrative Contacts ·
Reply With Quote
  #3  
Old 11-21-2008, 11:09 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
I've also noticed this. However, someArray()[2] will work.
__________________
Reply With Quote
  #4  
Old 11-22-2008, 05:44 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
May be you need to do "var in (someArray())" or so, the in-operator accepts several different formats so it might stumble if you just do "in func()"
Reply With Quote
  #5  
Old 11-22-2008, 07:58 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
var in {someArray()}?
Reply With Quote
  #6  
Old 11-22-2008, 08:36 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Quote:
Originally Posted by DustyPorViva View Post
var in {someArray()}?
No, ( ) instead of { }, although I bet both works.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #7  
Old 11-22-2008, 08:55 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
Quote:
Originally Posted by xXziroXx View Post
No, ( ) instead of { }, although I bet both works.
Well I said {} because that typically forces something into an array, right? Though I suspect this will also turn it into a subarray in an array... which will make it equally unusable. Just throwing the idea out there, though.


edit: I just copied and pasted your script, Novo, and it worked fine for me... at least on the serverside.

Weapon/GUI-script Personal/DustyPorViva/Test added/updated by DustyPorViva
Works!

edit2: works on the clientside too...
Reply With Quote
  #8  
Old 11-23-2008, 06:08 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Hmmm I remember there was some bug in older versions of the npcserver and clients where functions couldn't correctly return arrays.
Reply With Quote
  #9  
Old 11-24-2008, 02:35 PM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Ah. Alright. I had the problem on a Mac Intel version... I might have an outdated copy.
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 09:45 PM.


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