Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   weird bug [arrays] (https://forums.graalonline.com/forums/showthread.php?t=77389)

xAndrewx 10-31-2007 10:21 PM

weird bug [arrays]
 
well, it's odd.

Here's an array thing

HTML Code:

function onCreated()
{
  temp.array = { {"Heya", "Fish"}, {"hiya", "Bull"} };
  temp.search = {"Heya", "Fish"};
  echo(temp.array.index(temp.search));
}

However, it'd return a negative number, indicating that it can't be found!
Although, if I am to do this

HTML Code:

function onCreated()
{
  temp.array = { {"Heya", "Fish"}, {"hiya", "Bull"} };
  temp.search = {"Heya", "Fish"};
  echo(temp.array.index((@ temp.search)));
}

It'll give the correct array index... strange but true I must say

Inverness 10-31-2007 10:37 PM

Dynamic variables are fun.

Tolnaftate2004 10-31-2007 11:33 PM

It seems that var.index() only accepts strings as its parameter, so it's no bug.

Inverness: I don't think you caught what was being pointed out... :confused:

Novo 11-01-2007 12:12 AM

PHP Code:

function onCreated() 
{
  
temp.array = { {"Heya""Fish"}, {"hiya""Bull"} };
  
temp.search = {"Heya""Fish"};
  echo(
temp.array.index( @temp.search ) );


Here you go, love.

This is just because you're interpreting the object as it's input. There was something about Stefan claiming this a while ago. It was in one of the threads.... I'll see if I can find it.

Inverness 11-01-2007 03:18 AM

Quote:

Originally Posted by Tolnaftate2004 (Post 1355620)
Inverness: I don't think you caught what was being pointed out... :confused:

Don't worry, I did :D
Something about this was mentioned many months ago, its one of those weird Graal things. :D

Fix it Stefan >:O

Angel_Light 11-01-2007 04:41 AM

but abs() around to make it positive if it's the correct number XD lol, don't listen to me :P

Inverness 11-01-2007 06:04 AM

Quote:

Originally Posted by Angel_Light (Post 1355659)
but abs() around to make it positive if it's the correct number XD lol, don't listen to me :P

Wtf are you talking about?

Admins 11-03-2007 12:49 AM

You can't compare arrays with the == operator, that's why index() is not working with arrays either. If you convert it to string then it's comparing each array member with a string comparison and is return the wished index. This can also help if you want to find an object in an array with the same name, just give @object or object.name as parameter to the index() function.

bscharff 11-03-2007 02:23 AM

I was having issues with simple scripts not working because I didn't put a delimiter (@) in a place where it doesn't need to be.
Such As
player.chat = serverr.chat;
Would Have To Be
player.chat = @serverr.chat;
(Just an example - not necessarily one script with issues.)


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

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