AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Vector/array (https://forums.alliedmods.net/showthread.php?t=57445)

lagbeast 07-04-2007 20:36

Vector/array
 
Hi, my problem is simple. I want to have a vector called v and i want it to be [10] long and in it i want to store strings. I want to be able to add a string at a special place and i want to be able to delete a string at a place, also, i want to add data in the vector in the first empty place.

Now, my question is: How do i do that and should i use an array instead? If yes, how do i do that. Ive looked at http://www.amxmodx.org/funcwiki.php?go=inc&id=53 but im still not sure. Is there another site with more info on arrays/vectors or does someone just know how to do this?

stupok 07-04-2007 20:40

Re: Vector/array
 
Take a look at these:

http://wiki.alliedmods.net/index.php/Pawn_Tutorial

http://wiki.alliedmods.net/index.php...od_X_Scripting

_Master_ 07-05-2007 04:28

Re: Vector/array
 
If only PAWN had pointers....

lagbeast 07-05-2007 08:07

Re: Vector/array
 
Quote:

Originally Posted by stupok69 (Post 498796)

alright, im checking them out right now, it seems a bit stupid with the array for strings... and i cant find anything about vectors

lagbeast 07-05-2007 13:20

Re: Vector/array
 
Ok, so what i got from that is that u cant have an array of strings in an array. You can just have an array of chars that make a string? how the hell do you do when u want to have an array of strings then? Ive been searching for an article about vectors but with no luck. Are vectors the answer?

Rolnaaba 07-05-2007 13:53

Re: Vector/array
 
Quote:

Originally Posted by _Master_ (Post 498910)
If only PAWN had pointers....

aye...and typedefs...

stupok 07-05-2007 14:29

Re: Vector/array
 
Quote:

Originally Posted by lagbeast (Post 499069)
Ok, so what i got from that is that u cant have an array of strings in an array. You can just have an array of chars that make a string? how the hell do you do when u want to have an array of strings then? Ive been searching for an article about vectors but with no luck. Are vectors the answer?

You can have a multidimensional array.

Code:

new array_1d[64]
new array_2d[64][64]
new array_3d[64][64][64]


Rolnaaba 07-05-2007 14:36

Re: Vector/array
 
Um, I am not sure if I exactly understand you but here is an array of strings:
Code:
new StringArray[3][] = {     "String 1, Slot 0",     "String 2, Slot 1",     "String 3, Slot 2, finsihing out the array slots..." }; //close with a brace and optionaly semicolon.

lagbeast 07-05-2007 15:36

Re: Vector/array
 
Quote:

Originally Posted by Rolnaaba (Post 499106)
Um, I am not sure if I exactly understand you but here is an array of strings:
Code:
new StringArray[3][] = {     "String 1, Slot 0",     "String 2, Slot 1",     "String 3, Slot 2, finsihing out the array slots..." }; //close with a brace and optionaly semicolon.

I think you understood me! Thats what i wanted. So i guess this is how u would do it?

PHP Code:

new StrName[255] = "TEST"
new StringArray[10][]

StringArray[1][] = "poop"
StringArray[2][] = StrName 

is that possible or how do u do it if that doesnt work?

Rolnaaba 07-05-2007 17:16

Re: Vector/array
 
no, you cant delcare any varriable with an empty array "[]" without initializing it. Because you will get a compile error. The only reason "[]" exsists it tell the compiler to determine the required length for the string so you dont have to type it in, which it can only do if you have the string you want it to analyze there at the time.

fix:
Code:
new StrName[5] = "TEST" //TEST is only four characters, why make a 255 slotted array? new StringArray[10][5]; StringArray[1] = "poop" //only index the first array of your multidimensional array StringArray[2] = StrName //as long as the string is smaller or the same size as you second dimension, it will work.
But i am not sure you can do this in PAWN or not, or if it is safe...'

So do this instead:
Code:
new StrName[5] = "TEST"; new StringArray[10][5]; //[how many strings][length of string] copy(StringArray[1], 4, "poop"); copy(StringArray[2], 4, StrName);


All times are GMT -4. The time now is 21:28.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.