Array Copy Stock
1 Attachment(s)
I made this the other day because I could not find one. Maybe someone else will need it. It will copy data from one array to another for a max length of cells and you're able to set starting positions. If someone sees optimization errors or has any other, better, ideas feel free to edit/comment.
Code:
/** |
Re: Array Copy Stock
So you don't need to cast anything with that stock ?
|
Re: Array Copy Stock
I don't think so. Does pawn have an instanceof operator? Like to verify one bar type == another.
|
Re: Array Copy Stock
Technically Pawn is typeless but what he is refering to is tags matching up.
|
Re: Array Copy Stock
I know it's typeless. So a tags instanceof operator was what I was referring to.
|
Re: Array Copy Stock
You could just tag both into and from as any and you won't get any tag mismatches.
|
Re: Array Copy Stock
Quote:
|
Re: Array Copy Stock
Quote:
|
Re: Array Copy Stock
Quote:
|
Re: Array Copy Stock
Quote:
|
Re: Array Copy Stock
Quote:
|
Re: Array Copy Stock
Ya, why not do
Code:
if (tagof into != tagof from) PHP Code:
|
Re: Array Copy Stock
Quote:
Code:
if (0 != 0) Something you should also do is return the amount of values copied. |
Re: Array Copy Stock
So something like this
PHP Code:
|
Re: Array Copy Stock
Yes; however, you still need to tag both into and from as any so that any tag can be used. Currently it will give you a tag mismatch.
I suggest you move the tags to the end of the parameter list, so people don't have to use an underscore to skip the argument. I would also suggest a parameter for ignoring tags. Personally, how I would make it: Code:
stock arraycopy( any:into[], any:from[], len, bool:ignoretags = false, intotag = tagof into, intosize = sizeof into, intopos = 0, fromtag = tagof from, fromsize = sizeof from, frompos = 0) { |
Re: Array Copy Stock
Quote:
Also, why remove the error reporting? IMO, if the tags are not right when they should be, I think the client should be notified. |
Re: Array Copy Stock
Quote:
|
Re: Array Copy Stock
Did you test your stock ? Because I'm doing some tests just by curiosity, and by using tagof in the header will result 0 always or using multi-tag (any, or {Float, bool, etc..} ) and the value will be always the same (more the first tag). In others words, and if I don't say bullshits, it works only with mono-tag, and tagof has to used inside the function.
|
Re: Array Copy Stock
Quote:
|
Re: Array Copy Stock
Quote:
However, this works fine: Code:
arraycopy( copyarray, initarray, sizeof copyarray, .intotag = tagof copyarray, .fromtag = tagof initarray ); Something like: Code:
#define array_copy(%1, %2, %3) arraycopy( %1, %2, %3, .intotag = tagof %1, .fromtag = tagof %2 ) |
Re: Array Copy Stock
I'm putting together some tests right now. Tell me what it prints when you run this code...
Code:
new Float:a[5] = { 0.0, 1.0, ... }; |
Re: Array Copy Stock
Wooh, it's tricky. Using macro, indeed, tag is now well got. Good to know.
EDIT : Code:
Printing Test Values for Variable 'a' |
Re: Array Copy Stock
1 Attachment(s)
This is my output from the simple tests... Notice that the tags boolean doesn't do anything when the other parameters are not set properly.
Quote:
|
Re: Array Copy Stock
Quote:
Quote:
|
Re: Array Copy Stock
Tags are numbers ? I mean the the Float: tag is a specific number ?
|
Re: Array Copy Stock
You can say that, yes.
|
Re: Array Copy Stock
Quote:
|
Re: Array Copy Stock
Quote:
|
Re: Array Copy Stock
to copy arrays you can use something like this
Code:
new array1[5]={1,2,3,4,5} |
Re: Array Copy Stock
Quote:
Good one. |
Re: Array Copy Stock
Quote:
|
Re: Array Copy Stock
Ya, that's why you should test code before posting. It would also not be able to work on an array with data less than equal 0.
Use arrayset(array, value, size) arrayset(array2, array1[0], sizeof array2); Precondition that sizeof array1 <= array2. |
Re: Array Copy Stock
Quote:
you can try it in Pawn or other languages: C++,C# etc. |
Re: Array Copy Stock
You don't understand.
Code:
That will produce a runtime error of "index out of bounds" when i equals 3 since it isn't within the index range for the array. |
Re: Array Copy Stock
Quote:
|
Re: Array Copy Stock
Quote:
|
All times are GMT -4. The time now is 18:57. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.