Raised This Month: $51 Target: $400
 12% 

[SOLVED] Push ArrayList in ArrayList


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ESK0
BANNED
Join Date: May 2014
Location: Czech Republic
Old 06-28-2016 , 03:07   [SOLVED] Push ArrayList in ArrayList
Reply With Quote #1

Hello guys. im currently working on new ServerAdvertisements3 and i am using ArrayList to save everything from .cfg

Everything works great... but when i try to push array i just get error.

PHP Code:
error 035argument type mismatch (argument 2
But api says

PHP Code:
int size
If not setthe number of elements copied from the array will be equal to the blocksize. If set higher than the blocksizethe operation will be truncated
Code:
PHP Code:

  
#Globals
  
ArrayList aMessagesList;
  
ArrayList aMessages_Text;
  
ArrayList aMessages;


  
#OnPluginStart
  
aMessagesList = new ArrayList(1024);
  
aMessages_Text = new ArrayList(512);
  
aMessages = new ArrayList(512);

  
#Errors below
  
aMessages.PushArray(aMessages_Text);
  
aMessagesList.PushArray(aMessages); 
Can i even push ArrayList to ArrayList ? Im not very experienced with adt_arrays so probably i did something wrong

Thanks in advance

Last edited by ESK0; 06-29-2016 at 08:31.
ESK0 is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 06-28-2016 , 04:30   Re: Push ArrayList in ArrayList
Reply With Quote #2

ArrayLists are Handles, which are cells (ints).
PushArray is for pushing native arrays.
__________________
asherkin is offline
ESK0
BANNED
Join Date: May 2014
Location: Czech Republic
Old 06-28-2016 , 04:57   Re: Push ArrayList in ArrayList
Reply With Quote #3

Quote:
Originally Posted by asherkin View Post
ArrayLists are Handles, which are cells (ints).
PushArray is for pushing native arrays.
Thank you, I really appreciate it!
ESK0 is offline
ESK0
BANNED
Join Date: May 2014
Location: Czech Republic
Old 06-28-2016 , 05:27   Re: Push ArrayList in ArrayList
Reply With Quote #4

Now im fucked again...

Code:
PHP Code:
  aMessages.PushString(sMessageType);
  
aMessages.PushString(sMessageTag);
  
aMessages.Push(aMessages_Text);
  
aMessagesList.Push(aMessages);
  
aMessages.Clear();

  
aMessages aMessagesList.Get(iMessageCount-1);
  
char temptype[3];
  
aMessages.GetString(0temptypesizeof(temptype)); //Line 182

  
PrintToServer(temptype); 
Using - 1 becouse Arrays starts at 0 and my messages at 1

Errors:

PHP Code:
[SMException reportedInvalid index 0 (count0)
[
SMBlamingServerAdvertisements3.smx()
[
SMCall stack trace:
[
SM] [0ArrayList.GetString
[SM] [1Line 182
Again... Thanks in advance!

Edit: I am just a stupid dick head... anyway i figured it out but now i have another issue. -_-

PHP Code:
//Pushing to ArrayList

PushingIndexTypeTag: [1
PushingIndexTypeTag
Pushing
IndexTypeTag: [3
PushingIndexTypeTag
Pushing
IndexTypeTag: [5
PushingIndexTypeTag: [6

//Getting from ArrayList
RequestIndexTypeTag: [6]
RequestIndexTypeTag: [6]
RequestIndexTypeTag: [6]
RequestIndexTypeTag: [6]
RequestIndexTypeTag: [6]
RequestIndexTypeTag: [6
Im such confused..

Code:

PHP Code:
//Push

aMessages.PushString(sMessageType);
  
aMessages.PushString(sMessageTag);
  
aMessages.Push(aMessages_Text);
  
aMessagesList.Push(aMessages);
  
PrintToServer("Pushing: Index: %i | Type: %s | Tag: %s",iMessageCountsMessageType sMessageTag);
  
iMessageCount++;

//Request

for(int i 0iMessageCounti++)
  {
    
ArrayList temp aMessagesList.Get(i);
    
char type[3];
    
char tag[32];
    
temp.GetString(0typesizeof(type));
    
temp.GetString(1tagsizeof(tag));
    
PrintToServer("Request: Index: %i | Type: %s | Tag: %s",itypetag);
  } 
But when i do
PHP Code:
aMessages.PushString(sMessageType);
  
aMessages.PushString(sMessageTag);
  
aMessages.Push(aMessages_Text);
  
aMessagesList.Push(aMessages);
  
PrintToServer("Pushing: Index: %i | Type: %s | Tag: %s",iMessageCountsMessageType sMessageTag);


  
ArrayList temp aMessagesList.Get(iMessageCount);
  
char type[3];
  
char tag[32];
  
temp.GetString(0typesizeof(type));
  
temp.GetString(1tagsizeof(tag));
  
PrintToServer("Request: Index: %i | Type: %s | Tag: %s"iMessageCounttypetag);
  
iMessageCount++; 
Output is:

PHP Code:
PushingIndexTypeTag: [1]
RequestIndexTypeTag: [1]
PushingIndexTypeTag2
Request
IndexTypeTag2
Pushing
IndexTypeTag: [3]
RequestIndexTypeTag: [3]
PushingIndexTypeTag4
Request
IndexTypeTag4
Pushing
IndexTypeTag: [5]
RequestIndexTypeTag: [5]
PushingIndexTypeTag: [6]
RequestIndexTypeTag: [6

Last edited by ESK0; 06-28-2016 at 08:56.
ESK0 is offline
kuuichi
Junior Member
Join Date: May 2016
Location: los angeles
Old 06-28-2016 , 12:21   Re: Push ArrayList in ArrayList
Reply With Quote #5

What is iMessageCount? If you're just using iMessageCount to count the number of indices in aMessagesList, why not use just the aMessagesList.Length property?

I'm also confused relationally where these blocks of code are located, what is being executed and in what order? I ask because there is no possible way that this block of code would print more than two lines of output:

PHP Code:
aMessages.PushString(sMessageType); 
  
aMessages.PushString(sMessageTag); 
  
aMessages.Push(aMessages_Text); 
  
aMessagesList.Push(aMessages); 
  
PrintToServer("Pushing: Index: %i | Type: %s | Tag: %s",iMessageCountsMessageType sMessageTag); 


  
ArrayList temp aMessagesList.Get(iMessageCount); 
  
char type[3]; 
  
char tag[32]; 
  
temp.GetString(0typesizeof(type)); 
  
temp.GetString(1tagsizeof(tag)); 
  
PrintToServer("Request: Index: %i | Type: %s | Tag: %s"iMessageCounttypetag); 
  
iMessageCount++; 
kuuichi is offline
ESK0
BANNED
Join Date: May 2014
Location: Czech Republic
Old 06-28-2016 , 14:48   Re: Push ArrayList in ArrayList
Reply With Quote #6

Quote:
Originally Posted by kuuichi View Post
What is iMessageCount? If you're just using iMessageCount to count the number of indices in aMessagesList, why not use just the aMessagesList.Length property?

I'm also confused relationally where these blocks of code are located, what is being executed and in what order? I ask because there is no possible way that this block of code would print more than two lines of output:

PHP Code:
aMessages.PushString(sMessageType); 
  
aMessages.PushString(sMessageTag); 
  
aMessages.Push(aMessages_Text); 
  
aMessagesList.Push(aMessages); 
  
PrintToServer("Pushing: Index: %i | Type: %s | Tag: %s",iMessageCountsMessageType sMessageTag); 


  
ArrayList temp aMessagesList.Get(iMessageCount); 
  
char type[3]; 
  
char tag[32]; 
  
temp.GetString(0typesizeof(type)); 
  
temp.GetString(1tagsizeof(tag)); 
  
PrintToServer("Request: Index: %i | Type: %s | Tag: %s"iMessageCounttypetag); 
  
iMessageCount++; 
Hey How you doing ?

Here you go
PHP Code:

//Codde which does not work


public void CheckAllMessages()
{
  for(
int i 0aMessagesList.Lengthi++)
  {
    
ArrayList temp aMessagesList.Get(i);
    
char type[3];
    
char tag[32];
    
temp.GetString(0typesizeof(type));
    
temp.GetString(1tagsizeof(tag));
    
PrintToServer("Request: Index: %i | Type: %s | Tag: %s"itypetag);
  }
}
// Output

RequestIndexTypeTag: [6]
RequestIndexTypeTag: [6]
RequestIndexTypeTag: [6]
RequestIndexTypeTag: [6]
RequestIndexTypeTag: [6]
RequestIndexTypeTag: [6]

-------------------------------------------------------------------------------------------------

public 
void LoadMessages()
{
  
//Some code to open KeyValues etc..
    
kvMessages.GotoFirstSubKey();
    
AddMessagesToArray(kvMessages);
    while(
kvMessages.GotoNextKey())
    {
      
AddMessagesToArray(kvMessages);
    }
}

public 
void AddMessagesToArray(KeyValues kv)
{
  
aMessages.Clear();
  
aMessages_Text.Clear();

  
char sMessageType[3];
  
char sMessageTag[32];
  
char sTempLanguageName[12];
  
char sTempLanguageMessage[512];
  
kv.GetString("type"sMessageTypesizeof(sMessageType), "T");
  
kv.GetString("tag"sMessageTagsizeof(sMessageTag));
  for(
int i 0aLanguages.Lengthi++)
  {
    
aLanguages.GetString(isTempLanguageNamesizeof(sTempLanguageName));
    
kv.GetString(sTempLanguageNamesTempLanguageMessagesizeof(sTempLanguageMessage), "NOLANG");
    if(
StrEqual(sTempLanguageMessage"NOLANG"))
    {
      
kv.GetString("default"sTempLanguageMessagesizeof(sTempLanguageMessage));
    }
    
aMessages_Text.PushString(sTempLanguageMessage);
  }
  
aMessages.PushString(sMessageType);
  
aMessages.PushString(sMessageTag);
  
aMessages.Push(aMessages_Text);
  
aMessagesList.Push(aMessages);
  
PrintToServer("Pushing: Index: %i | Type: %s | Tag: %s",aMessagesList.Length-1sMessageType sMessageTag);


  
ArrayList temp aMessagesList.Get(aMessagesList.Length-1);
  
char type[3];
  
char tag[32];
  
temp.GetString(0typesizeof(type));
  
temp.GetString(1tagsizeof(tag));
  
PrintToServer("Request: Index: %i | Type: %s | Tag: %s"aMessagesList.Length-1typetag);
}

//Output
PushingIndexTypeTag: [1]
RequestIndexTypeTag: [1]
PushingIndexTypeTag2
Request
IndexTypeTag2
Pushing
IndexTypeTag: [3]
RequestIndexTypeTag: [3]
PushingIndexTypeTag4
Request
IndexTypeTag4
Pushing
IndexTypeTag: [5]
RequestIndexTypeTag: [5]
PushingIndexTypeTag: [6]
RequestIndexTypeTag: [6
I dont really get it..
ESK0 is offline
kuuichi
Junior Member
Join Date: May 2016
Location: los angeles
Old 06-28-2016 , 15:55   Re: Push ArrayList in ArrayList
Reply With Quote #7

I'm great!

In your LoadMessages() function, I don't think (not sure though) you need GoToFirstSubKey(), I think it's implicit that calling GotoNextKey() for the first time will send you to the first key so this would be fine assuming you didn't set the cursor position somewhere else:

PHP Code:
public void LoadMessages() {
    while (
kvMessages.GotoNextKey(kvMessages)) {
        
AddMessagesToArray();
    }

After looking over your code I'm quite confused too - perhaps this is due to the compiler confusing your temporary ArrayLists? I remember reading that SourcePawn does not have garbage collection, so it's generally good practice to delete Handles when you don't need them anymore anyway. How about trying this:

PHP Code:
public void CheckAllMessages() 

  for(
int i 0aMessagesList.Lengthi++) 
  { 
    
ArrayList temp aMessagesList.Get(i); 
    
char type[3]; 
    
char tag[32]; 
    
temp.GetString(0typesizeof(type)); 
    
temp.GetString(1tagsizeof(tag)); 
    
PrintToServer("Request: Index: %i | Type: %s | Tag: %s"itypetag);
    
// Delete temp after you use it as you're going to reassign it anyway
    
delete temp;
  } 

Also in AddMessagesToArray() I would delete it as well:

PHP Code:
ArrayList temp aMessagesList.Get(aMessagesList.Length-1); 
char type[3]; 
char tag[32]; 
temp.GetString(0typesizeof(type)); 
temp.GetString(1tagsizeof(tag)); 
PrintToServer("Request: Index: %i | Type: %s | Tag: %s"aMessagesList.Length-1typetag); 
delete temp
I'm not sure if this is going to fix your problem, but it's a start in the right direction.
__________________
i guess i have a picture of jon skeet as my avatar

Last edited by kuuichi; 06-28-2016 at 15:56.
kuuichi is offline
ESK0
BANNED
Join Date: May 2014
Location: Czech Republic
Old 06-29-2016 , 02:19   Re: Push ArrayList in ArrayList
Reply With Quote #8

Hey, Thanks for your suggestions.. But i just recode whole push and get part.. remove some globals and make them temp and now i use only one global a its aMessagesList..

Now it works as charm )

//Output
Spoiler


//Config
Spoiler


Thank you to all of you

Last edited by ESK0; 06-29-2016 at 02:20.
ESK0 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 01:37.


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