AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Moving a String into a array (https://forums.alliedmods.net/showthread.php?t=6695)

EKS 10-11-2004 00:34

Moving a String into a array
 
Code:
new MyString[84] = "de_dust de_aztec de_nuke de_inferno"

Now, i need a way to split this string up into this array
Code:
new MyArray[20][20]
But the problem, is that MyString will not allways contain the same ammunt of words, So i need a way thats more "dynamic".

I tried doing:
Code:
    for(new i=1;i<=g_NumberOfMaps;i++)          parse(MyString,MyArray[i],23)
But then it only copies the first Text ( in this case de_dust) over and over. So if someone can think of a nice and clean way of this it would save me a head ake.

twistedeuphoria 10-11-2004 00:51

How about doing something like:
Code:
new len,mystring[84],i len = format(mystring,83,"w/e") for(i=0;blah;i++)    len += format(mystring[len],83-len,"new w/e")

then parse it like:
Code:
 parse(mystring,myarray[0],19 ... etc etc)

BAILOPAN 10-11-2004 01:33

parse is bad. create a maximum limit to the size and work from there to manually break the string.

Zor 10-11-2004 10:04

Hmmm...You could use Parse and Array. Are you getting this text from a text file? So instead of Parse use the new one:

Code:

strtok(const text[], Left[], leftLen, Right[], rightLen, token=' ', trimSpaces=0)
I'll assume that strtok will return the length of the string taken....

So I would look at it like this:

Code:

//Global
new MyString[84] = "de_dust de_aztec de_nuke de_inferno"
new MyArray = new_list_string()

public plugin_cfg()
{
    new mapName[32]

    while((strtok(MyString, mapName, 31, MyString, 83, ' ', 1)) > 0)
    {
          list_push_string(MyArray, mapName)
    }
}
....
Code
....

public plugin_end()
{
    list_delete_string(MyArray)
}
....
Code
....

public MapChange(param[])
{
    new positonIwant = str_to_num(param[0])
    new mapName[32]
    list_get_string ( MyArray, positonIwant, mapName, 31)
    server_cmd("changelevel %s", mapName)
}

Well thats about it. Now thats about as dynamic as you can get it. And there are probably some errors in it. But its an idea.

Cheers!

PM 10-11-2004 12:03

You could try BAILOPAN's array module to make it more dynamic.

devicenull 10-11-2004 12:16

Code:
new len=0, i=0 while (len >= strlen(mymaps)) { len = copyc(mymaps[len],maps[i],32) i++ }
Should work, I can't really remember the correct syntax for it atm

Zor 10-11-2004 12:31

Ummmm....thats what I put PM!!! Heheheheh

Cheers!

Johnny got his gun 10-11-2004 15:49

I think I solved something similar along time ago by using parse, getting one word at a time. Right after parse I cut that parsed chunk off, and reparsed until I got it all.
Nothing dynamic about the array to store to though. Small is the opposite of dynamic :-\

Zor 10-11-2004 16:30

True, but with the Array Module you get the Dynamics! Which is great!

EKS 10-11-2004 17:59

Quote:

Originally Posted by Johnny got his gun
I think I solved something similar along time ago by using parse, getting one word at a time. Right after parse I cut that parsed chunk off, and reparsed until I got it all.
Nothing dynamic about the array to store to though. Small is the opposite of dynamic :-\

perhaps dynamic is not the right word.
But the amont of words(maps) is gonna change . so it needs to work with "any" amount of maps.
What plugin did you do this in?


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

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