Page 1 of 1

Array as sub parameter problem

Posted: Wed Aug 18, 2004 7:22 am
by Nightcrawler7514
Im trying to pass an array from one sub to another, but for some reason it doesnt work.

Code: Select all

Sub Main
  /declare TT int outer
  /call IniArrayCount Hunter.ini "Settings" "Buff" ${TT}
  /varset TT ${Macro.Return}
  /echo ${TT}
  /declare TArray[${TT}] string outer
  /call ReadINIArray Hunter.ini "Settings" "Buff" ${TArray}
/return

Sub IniArrayCount(string INIFile, string Section, string Line, int Counter)
  /varset Counter 1
  
  :CounterLoop
    /if (${String[${Ini[${INIFile},${Section},${Line}${Counter}]}].Equal[null]}) {
      /varcalc Counter ${Counter}-1
      /goto :EndLoop
    }
    /varcalc Counter ${Counter}+1
  /goto :CounterLoop
  
  :EndLoop
/return ${Counter}

Sub ReadINIArray(string INIFile, string Section, string Line,  Array)
  /echo ${Array.Size}
/return
Could someone tell me what Im doing wrong?

Nightcrawler7514

Posted: Wed Aug 18, 2004 11:23 am
by Mimatas

Code: Select all

/declare TArray[${TT}] string outer 
IniArrayCount will already know it's there without having to pass it, since you declared it as an outer.

Posted: Wed Aug 18, 2004 1:25 pm
by Nightcrawler7514
Maybe I didnt clearify enough.

What I want is a generic function that takes 3 strings and an array as arguments and returns the array with the content from an INI file that are specified in the 3 strings.

Code: Select all

Sub Main 
  /declare TT int outer 
  /call IniArrayCount Hunter.ini "Settings" "Buff" ${TT} 
  /varset TT ${Macro.Return} 
  /echo ${TT} 
  /declare TArray[${TT}] string outer 
  /call ReadINIArray Hunter.ini "Settings" "Buff" ${TArray}
/return 

Sub IniArrayCount(string INIFile, string Section, string Line, int Counter) 
  /varset Counter 1 
  
  :CounterLoop 
    /if (${String[${Ini[${INIFile},${Section},${Line}${Counter}]}].Equal[null]}) { 
      /varcalc Counter ${Counter}-1 
      /goto :EndLoop 
    } 
    /varcalc Counter ${Counter}+1 
  /goto :CounterLoop 
  
  :EndLoop 
/return ${Counter} 

Sub ReadINIArray(string INIFile, string Section, string Line,  Array) 
  /echo ${Array.Size} 
/return 
The IniArrayCount only counts the number of items in the INI file and has nothing to do with the array, other than desiding the side of the declared array after it has been called. The problem is with the ReadINIArray function, I cant get that to take an array. I have tried different things but no go

If someone could help me I would really appriciate it

Nightcrawler

Posted: Wed Aug 18, 2004 2:57 pm
by Rusty~
i'm not completely sure what you need, but if you declare an array as outer, you can pass the name of the array to the sub as a string and then access it like this:

Code: Select all

Sub ReadINIArray(string INIFile, string Section, string Line,  ArrayName) 
  /echo ${${ArrayName}.Size} 
/return 

Posted: Thu Aug 19, 2004 12:06 am
by Nightcrawler7514
Hmm. Hadden even ocured to me to do it that way, and it will solve another problem I had at the same time. Thanks Rusty~

Nightcrawler