Copying an array - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Copying an array (
/showthread.php?tid=412575)
Copying an array -
Misiur - 02.02.2013
pawn Код:
enum StrongTag {
var,
str[32],
Float:dim
}
new Type[StrongTag] = {
1,
"wat",
-1.0
};
new Car[StrongTag];
stock Foo(arr[]) {
Car = arr;
return 1;
}
main() {
Foo(Type);
}
This code is invalid, and I don't know how to resolve it. I don't want to pass arguments one by one, and I'm looking for solution which will allow me to copy whole array. Also I think that string causes creation of another dimension, and I don't know what to do with it. Can pointers help me in achieving this?
Search function on this forum is terrible :c
Re: Copying an array -
Misiur - 02.02.2013
Logic fail on my part. I am clueless in this matter. Let's say I have currently something like
pawn Код:
enum StrongTag {
var,
str[10],
Float:dim
}
new Bar[StrongTag] = {
1,
"sup",
-1.0
};
new Car[StrongTag];
stock Foo(v, s[], Float:d) {
Car[var] = v;
strcpy(Car[str], s);
Car[dim] = d;
return 1;
}
main() {
Foo(Bar[var], Bar[str], Bar[dim]);
}
However I know that the StrongTag enum will grow, and there won't be two variables, but ~25, and I'd have to find all calls to Foo, pass additional arguments, and change Foo definition - scalability is important in this project.
I saw
https://sampforum.blast.hk/showthread.php?tid=337110 but I don't know how to apply it in this case.
Re: Copying an array -
Misiur - 02.02.2013
I'm not getting anywhere near it, am I? Changed to weak tag for testing purposes
pawn Код:
enum weakTag {
var,
Float:dim
}
new Type[weakTag] = {
1,
-1.0
};
new Car[weakTag];
stock Foo(const v[]) {
Car = weakTag:v; //Line 53
return 1;
}
stock FooBar(v) {
Car = weakTag:v; //Line 57
return 1;
}
stock FooBarFoo(weakTag:v) {
Car = weakTag:v; //Line 61
return 1;
}
stock FooBarFooBar(weakTag:v[]) {
Car = v; //Line 65
return 1;
}
main() {
Foo(Type);
FooBar(Type); //Line 71
FooBarFoo(Type);
FooBarFooBar(Type);
new weakTag:Tmp;
Foo(Tmp);
FooBar(Tmp);
FooBarFoo(Tmp);
FooBarFooBar(Tmp);
}
Quote:
truck.pwn(53) : error 047: array sizes do not match, or destination array is too small
truck.pwn(57) : error 033: array must be indexed (variable "Car")
truck.pwn(61) : error 033: array must be indexed (variable "Car")
truck.pwn(65) : error 047: array sizes do not match, or destination array is too small
truck.pwn(71) : error 035: argument type mismatch (argument 1)
truck.pwn(72) : error 035: argument type mismatch (argument 1)
truck.pwn(73) : warning 213: tag mismatch
truck.pwn(75) : error 035: argument type mismatch (argument 1)
truck.pwn(7 : error 035: argument type mismatch (argument 1)
|
Errors only about array sizes look promising, I've run something like
pawn Код:
stock Foo(const v[], s = sizeof v) {
printf("%d %d", sizeof Car, s);
return 1;
}
And I get "2 2"
Re: Copying an array -
Misiur - 02.02.2013
Hah, I don't know why I've assumed that you can't pass argument like that. Well, thanks for making me think!