Ini for items.

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

Moderator: MacroQuest Developers

Banannaboy
a lesser mummy
a lesser mummy
Posts: 43
Joined: Tue Apr 13, 2004 9:59 pm

Ini for items.

Post by Banannaboy » Sat May 15, 2004 1:00 am

I am trying to write a macro that will make an ini file with all the items and the prices that merchants will give to me. (Well not all the items, but all the items that I sell).

My ini looks like

Code: Select all

[names] 
val1=Words of crap
val2=sword of uberness

[prices]
val1=1000  |set price for 1p
val2=25000 |set price for 25p
I know the macro will have to be something like

Code: Select all

#event create "#*#I'll give you #1# platinum#*#for the #2#.'"
#event create "#*#I'll give you #1# platinum#*#per #2#"
Sub main
/declare File string outer
/declare Counter string outer
/varset File items.ini

:Loop
/doevents
/goto :Loop
/endmacro

Sub Event_create(Line, Plats, ItemName)
/ini ${File} names val${Counter} "${ItemName}"
/ini ${File} prices val${Counter} ${Plats}000
/varcalc Counter ${Counter}+1
/ini ${File} counter c1 ${Counter}
/varcalc Counter ${Counter}-1
/echo Created ${Counter} entry. ${ItemName} set for ${Plats} plat.!
/return
But I cant get that to work right. Im new to working with ini's. What am I doing wrong?

Preocts
a snow griffon
a snow griffon
Posts: 312
Joined: Thu Jan 29, 2004 1:02 pm

Post by Preocts » Sat May 15, 2004 8:08 am

Why do you define Counter as a string and then try to do math with it?


Okay, assuming we define Counter as an int so it's an actual mathmatical number let's take a look here:

Code: Select all

Sub Event_create(Line, Plats, ItemName) 
/ini ${File} names val${Counter} "${ItemName}" 
/ini ${File} prices val${Counter} ${Plats}000 
/varcalc Counter ${Counter}+1 [color=green]<------- Okay I follow this[/color]
/ini ${File} counter c1 ${Counter} 
/varcalc Counter ${Counter}-1  [color=red]<------- This confuses me. Counter is never incrementing because you never pull the value you just stored.[/color]
/echo Created ${Counter} entry. ${ItemName} set for ${Plats} plat.! 
/return 

Banannaboy
a lesser mummy
a lesser mummy
Posts: 43
Joined: Tue Apr 13, 2004 9:59 pm

Post by Banannaboy » Sat May 15, 2004 12:46 pm

Ah I see what you mean. And this fixed the counter problem.

Code: Select all

#event create "#*#I'll give you #1# platinum#*#for the #2#.'" 
#event create "#*#I'll give you #1# platinum#*#per #2#" 
Sub main 
/declare File string outer 
/declare Counter [color=cyan]int[/color] outer 
/varset File items.ini 

:Loop 
/doevents 
/goto :Loop 
/endmacro 

Sub Event_create(Line, Plats, ItemName)
[color=cyan]/varset Counter ${Ini[${File},counter,c1]}[/color]
/ini ${File} names val${Counter} "${ItemName}" 
/ini ${File} prices val${Counter} ${Plats}000 
/varcalc Counter ${Counter}+1 
/ini ${File} counter c1 ${Counter} 
/varcalc Counter ${Counter}-1 
/echo Created ${Counter} entry. ${ItemName} set for ${Plats} plat.! 
/return
But now when I try the macro I am having a different problem. Say my ini looks like this before running the macro.

Code: Select all

[names] 
val1=Words of crap

[values]
val1=1000  |set price for 1p

[counter]
c1=2
But then when I run the macro, and it grabs the item that I am selling, it creates 2 different values for the one item. The ini looks like this after trying to sell "Small Banded Sleeves"

Code: Select all

[names] 
val1=Words of crap
val2=for the Small Banded Sleeves.'
val3=Small Banded Sleeves

[prices]
val1=1000  |set price for 1p
val2=1000
val3=1000

[counter]
c1=4
and I am getting 2 echos. The first echo is thinking the item name is "for the small banded sleeves.'" but the second echo gets it perfect. Why is the event being trigged twice when I try to sell an item and why is the first one getting the item name wrong??

Preocts
a snow griffon
a snow griffon
Posts: 312
Joined: Thu Jan 29, 2004 1:02 pm

Post by Preocts » Sun May 16, 2004 7:02 am

Code: Select all


#event create "#*#I'll give you #1# platinum #*# for the #2#.'" 
#event create "#*#I'll give you #1# platinum #*# per #2#" 

Try that. Question for you again.

Code: Select all


Sub Event_create([color=red]Line, Plats, ItemName[/color])

Why three parameters when you are pulling two from the event? From my view it would return Plats, ItemName.

Edit: Answered my own question. Okay, that makes sense... only thing I can see that might cause the event to hit twice like it is would be the spacing.
Last edited by Preocts on Sun May 16, 2004 8:44 am, edited 1 time in total.

smelly wang
a lesser mummy
a lesser mummy
Posts: 54
Joined: Mon Jan 19, 2004 6:04 pm

Post by smelly wang » Sun May 16, 2004 7:53 am

whats the point in increasing counter and then decreasing it again? this should work....

Code: Select all

#event create "#*#I'll give you #1# platinum#*#for the #2#.'"
#event create "#*#I'll give you #1# platinum#*#per #2#"
Sub main
/declare File string outer
/declare Counter int outer
/varset File items.ini
/varset Counter ${Ini[${File},counter,c1]}

:Loop
/doevents
/goto :Loop
/endmacro

Sub Event_create(Line, Plats, ItemName)
/varset Counter ${Ini[${File},counter,c1]}
/ini ${File} names val${Counter} "${ItemName}"
/ini ${File} prices val${Counter} ${Plats}000
/varcalc Counter ${Counter}+1
/ini ${File} counter c1 ${Counter}
/echo Created ${Counter} entry. ${ItemName} set for ${Plats} plat.!
/return

Preocts
a snow griffon
a snow griffon
Posts: 312
Joined: Thu Jan 29, 2004 1:02 pm

Post by Preocts » Sun May 16, 2004 8:16 am

Code: Select all

Sub Event_create(Line, Plats, ItemName) 
/varset Counter ${Ini[${File},counter,c1]} 
/ini ${File} names val${Counter} "${ItemName}" 
/ini ${File} prices val${Counter} ${Plats}000 
[color=red]/echo Created ${Counter} entry. ${ItemName} set for ${Plats} plat.! [/color]
/varcalc Counter ${Counter}+1 
/ini ${File} counter c1 ${Counter} 
/return
:) That was really a moot point as I wasn't worried about what he was doing or how. Just about getting it working.