Is %ruleNo (=1,2,3,4...) refering to the "1=" or refering to the first line then second line and so on... ?
Take a moment to meditate on /help $hget

$hget(table,item) will return the data for the item of that
name.
So far your gift names were consecutive numbers - a numerical loop could access each gift directly: to access the Nth item, just access item with
name N.
As you now want the gift names (items) to be something else, the loop has first to compute the name of the Nth item:
$hget(table,N).item to return the name of the Nth item, then either $hget(table,itemname) or $hget(table,N).data to acces it's data.
Also note that hash tables inherently are unsorted: the Nth item isn't necessarily the
first item of your ini file.
alias check {
var %gifts, %ruleNo = 1
; loop for Nth rule
while ($hget(gift.rules,%ruleNo).item != $null) {
; store item name (giftname) and get it's data (string of gift conditions)
var %giftname = $v1, %data = $hget(gift.rules,%ruleNo).data
; parse that string, check conditions
var %required.rating = $gettok(%data,1,32), %required.ranking = $gettok(%data,2,32)
if ($hget(rating,$1) > %required.rating) && ($hget(ranking,$1) > %required.ranking) {
; all conditions met: add the current gift to the string of gifts-to-get
var %gifts = $addtok(%gifts,%giftname,59)
}
; continue with next rule
inc %ruleNo
}
; all rules processed: output result with the gifts sorted alphanumerically
ECHO -a $1 will be given : $sorttok(%gifts,59,a)
}Regarding your second question: there are several approaches to it...
One question is whether to store the country data in the name of the user, or store it as a separate value (like the rating/ranking values in separate tables).
Then, whether to add "country" simply as another condition-to-meet (being a new column of the rules chart) - or to use separate ini sections. For the latter, the script should load each section to a separate table.
As your script is for checking users individually, these questions don't matter in regard to performance, but in regard to useability and data management. If you have problems to anticipate the pros and cons of each layout, why not try out in actual code?

Example, for the case that you decide to store the country as a part of the username, and opt for separate ini topics
/addname Name1.fr 3 100
/addname Name2.fr 5.2 100
/addname Name3.fr 8 60
/addname Name1.uk 7 50
/addname Name2.uk 8.5 600
/addname Name3.uk 2 60
[giftrules_fr]
book_fr=0 0
ball=4 50
DVD_fr=6 50
Apple=2 80
[giftrules_uk]
book_en=0 0
ball=4 60
DVD_en=6 250
Banana=8 10
[giftrules_de]
book=0 0
ball=3 32
DVD=7 250
alias loadrules {
; loop all ini topics
var %n = 1
while ($ini(giftrules.ini,%n)) {
var %topic = $v1
; load topic into a hash table of the same name
if ($hget(%topic)) { hfree %topic }
hmake %topic
hload -i %topic giftrules.ini %topic
inc %n
}
}
alias check {
; "country" is the last dot-delimited token of the username
var %country = $gettok($$1,-1,46)
var %gifts, %ruleNo = 1
; loop all the rules of the table of that country
var %table = giftrules_ $+ %country
while ($hget(%table,%ruleNo).item != $null) {
; store item name (giftname) and get it's data (string of gift conditions)
var %giftname = $v1, %data = $hget(%table,%giftname)
; parse that string, check conditions
var %required.rating = $gettok(%data,1,32), %required.ranking = $gettok(%data,2,32)
if ($hget(rating,$1) > %required.rating) && ($hget(ranking,$1) > %required.ranking) {
; all conditions met: add the current gift to the string of gifts-to-get
var %gifts = $addtok(%gifts,%giftname,59)
}
; continue with next rule
inc %ruleNo
}
; all rules processed: output result with the gifts sorted alphanumerically
ECHO -a $gettok($1,1--2,46) from %country will be given : $sorttok(%gifts,59,a)
}Result:
Name1 from fr will be given : Apple;book_fr
Name2 from fr will be given : Apple;ball;book_fr
Name3 from fr will be given : ball;book_fr;DVD_fr
Name1 from uk will be given : ball;book_en
Name2 from uk will be given : ball;Banana;book_en;DVD_en
Name3 from uk will be given : book_en