Array as sub parameter problem

Need help with a macro you are writing? Ask here!

Moderator: MacroQuest Developers

Nightcrawler7514
orc pawn
orc pawn
Posts: 25
Joined: Mon Oct 27, 2003 6:43 pm
Location: Denmark

Array as sub parameter problem

Post by Nightcrawler7514 » Wed Aug 18, 2004 7:22 am

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

Mimatas
a hill giant
a hill giant
Posts: 262
Joined: Wed Mar 10, 2004 4:22 pm

Post by Mimatas » Wed Aug 18, 2004 11:23 am

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.

Nightcrawler7514
orc pawn
orc pawn
Posts: 25
Joined: Mon Oct 27, 2003 6:43 pm
Location: Denmark

Post by Nightcrawler7514 » Wed Aug 18, 2004 1:25 pm

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

Rusty~
a hill giant
a hill giant
Posts: 244
Joined: Wed Apr 14, 2004 2:55 pm

Post by Rusty~ » Wed Aug 18, 2004 2:57 pm

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 

Nightcrawler7514
orc pawn
orc pawn
Posts: 25
Joined: Mon Oct 27, 2003 6:43 pm
Location: Denmark

Post by Nightcrawler7514 » Thu Aug 19, 2004 12:06 am

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