• Advertisement
Sign in to follow this  

Problem with array of handles

This topic is 1521 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement