Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


- - - - -

Problem with array of handles


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Bitsauce   Members   -  Reputation: 235

Like
0Likes
Like

Posted 13 November 2013 - 03:15 PM

Hi again!

It seems I've encountered a bug in the newest version of the scriptarray add-on (tested rev1771 also). AngelScript yields the following error:

 

 

'Type 'A' does not have a matching opEquals or opCmp method'

... When i run something like this:
 

class A {}

array<A@> list;

void main() {
    A a;
    list.insertLast(@a);
    int idx = list.find(@a); // ERROR
}

I'm sure there is an easy fix for this, but knowing me I'll probably take ages to figure it out, so for the time being I think I'll just revert back to an older version of the add-on tongue.png.
 


Edited by Marcus L, 14 November 2013 - 07:14 AM.


Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3437

Like
0Likes
Like

Posted 13 November 2013 - 05:10 PM

It's not a bug. The array currently use the opEquals or opCmp of the object when using find (or sort), where it previously did a direct compare of the pointers. This was changed recently as otherwise there was no way doing a find or sort by value in arrays of handles. 

 

But I see your point. I'll probably need to add an additional method for doing an exact match which compares the pointers, so for arrays of object handles it will have both options. 

 

This is similar to the difference between the operators == and is. The former does a value comparison, and the latter does an address comparison.


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#3 Bitsauce   Members   -  Reputation: 235

Like
0Likes
Like

Posted 14 November 2013 - 07:02 AM

Oh, i guess that does make sense smile.png
 

 

This is similar to the difference between the operators == and is.The former does a value comparison, and the latter does an address comparison.

Wait. So does this mean that something like @objectA == @objectB will perform a value comparison? Or is when you omit the '@'s that a value comparison will be done?

I have a suggestion on how the original problem can be solved, but as i don't know the inner workings of AngelScript, i don't know if this is too difficult to pull off. However, what i thought could work, is when the script writer wrote something like "list.find(@a)", then AS would interpret this as look for the handle of 'a' in the list, while if the script writer wrote "list.find(a)", then it would be interpreted as look for the value of 'a' in the list (using opCmp).

Anyways, thanks for clearing that up smile.png !


Edited by Marcus L, 14 November 2013 - 08:04 AM.


#4 Andreas Jonsson   Moderators   -  Reputation: 3437

Like
0Likes
Like

Posted 14 November 2013 - 11:13 AM

By using the @ symbol you explicitly say the expression should operate on the address, thus @objectA == @objectB is identical to objectA is objectB, and perform a comparison of the handles. objectA == objectB does a comparison of the values using opEquals (or opCmp if the former doesn't exist).

 

 

Since the find method of the array of handles takes as parameter a handle, the compiler will implictly convert any expression to a handle even if the script writer doesn't use the @ symbol.

 

object @a;

array<object@> list;

list.find(@a);   // explicitly pass the handle

list.find(a);    // implicitly pass the handle

 

I'm thinking about resolving this by adding an optional boolean argument where the script can specifically mention if the comparison should be done by value or by address. It will then be something like this:

 

array<int> a;

a.find(42);         // By default value comparison is performed

array<object@> b;

b.find(obj, true);  // Explciticly inform search by address comparison

b.find(obj, false); // Explictly inform search by value comparison

 

 

But I'll need to give this some more thought before implementing it.


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#5 Jake Albano   Members   -  Reputation: 649

Like
0Likes
Like

Posted 15 November 2013 - 08:30 AM

I'll just chime in here and say that it isn't especially obvious what the bool parameter in find() would do. It might be clearer to name it something like findByRef(). Just my two cents. smile.png


Edited by Jake Albano, 15 November 2013 - 08:30 AM.


#6 Jason Goepel   Members   -  Reputation: 441

Like
0Likes
Like

Posted 15 November 2013 - 02:08 PM

I agree with Jake that an additional method might be more clear.



#7 Andreas Jonsson   Moderators   -  Reputation: 3437

Like
1Likes
Like

Posted 15 November 2013 - 09:05 PM

Yes, you're right. Two different functions with appropriate names is better.


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#8 Andreas Jonsson   Moderators   -  Reputation: 3437

Like
2Likes
Like

Posted 23 November 2013 - 09:50 AM

I've implemented the findByRef in revision 1785


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS