Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Bug Report (https://forums.graalonline.com/forums/forumdisplay.php?f=193)
-   -   "in" operator on returned array. (https://forums.graalonline.com/forums/showthread.php?t=82851)

Novo 11-21-2008 04:41 PM

"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.");
  }



TSAdmin 11-21-2008 04:59 PM

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.

cbk1994 11-21-2008 11:09 PM

I've also noticed this. However, someArray()[2] will work.

Admins 11-22-2008 05:44 PM

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()"

DustyPorViva 11-22-2008 07:58 PM

var in {someArray()}?

xXziroXx 11-22-2008 08:36 PM

Quote:

Originally Posted by DustyPorViva (Post 1444059)
var in {someArray()}?

No, ( ) instead of { }, although I bet both works.

DustyPorViva 11-22-2008 08:55 PM

Quote:

Originally Posted by xXziroXx (Post 1444068)
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...

Admins 11-23-2008 06:08 PM

Hmmm I remember there was some bug in older versions of the npcserver and clients where functions couldn't correctly return arrays.

Novo 11-24-2008 02:35 PM

Ah. Alright. I had the problem on a Mac Intel version... I might have an outdated copy.


All times are GMT +2. The time now is 07:31 PM.

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