Raised This Month: $ Target: $400
 0% 

Vector/array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lagbeast
Junior Member
Join Date: Jul 2007
Old 07-04-2007 , 20:36   Vector/array
Reply With Quote #1

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?
lagbeast is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 07-04-2007 , 20:40   Re: Vector/array
Reply With Quote #2

Take a look at these:

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

http://wiki.alliedmods.net/index.php...od_X_Scripting
stupok is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 07-05-2007 , 04:28   Re: Vector/array
Reply With Quote #3

If only PAWN had pointers....
_Master_ is offline
Rolnaaba
Veteran Member
Join Date: May 2006
Old 07-05-2007 , 13:53   Re: Vector/array
Reply With Quote #4

Quote:
Originally Posted by _Master_ View Post
If only PAWN had pointers....
aye...and typedefs...
__________________
DO NOT PM me about avp mod.
Rolnaaba is offline
lagbeast
Junior Member
Join Date: Jul 2007
Old 07-05-2007 , 08:07   Re: Vector/array
Reply With Quote #5

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 is offline
lagbeast
Junior Member
Join Date: Jul 2007
Old 07-05-2007 , 13:20   Re: Vector/array
Reply With Quote #6

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?
lagbeast is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 07-05-2007 , 14:29   Re: Vector/array
Reply With Quote #7

Quote:
Originally Posted by lagbeast View Post
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]
stupok is offline
Rolnaaba
Veteran Member
Join Date: May 2006
Old 07-05-2007 , 14:36   Re: Vector/array
Reply With Quote #8

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.
__________________
DO NOT PM me about avp mod.

Last edited by Rolnaaba; 07-05-2007 at 14:38.
Rolnaaba is offline
lagbeast
Junior Member
Join Date: Jul 2007
Old 07-05-2007 , 15:36   Re: Vector/array
Reply With Quote #9

Quote:
Originally Posted by Rolnaaba View Post
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?
lagbeast is offline
Rolnaaba
Veteran Member
Join Date: May 2006
Old 07-05-2007 , 17:16   Re: Vector/array
Reply With Quote #10

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);
__________________
DO NOT PM me about avp mod.
Rolnaaba is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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