PDA

View Full Version : quest global vars : wildcards behavior


smogo
03-02-2004, 03:27 PM
i was a bit worried about the way the global variables are organized :

whenever you set a variable 'name' to 'value', the code checks for var with such name that already applies, and removes them. e.g you can't have a (charid, name) variable if (otherchar, name), or (anychar, name). Such variables would apply, you would retrieve them, and the code prevents ambigous cases where you get 2 values for a name (as charid is one of anychar)


// clean up expired vars and get rid of the one we're going to set if there
database.RunQuery(query, MakeAnyLenString(&query,
"DELETE FROM quest_globals WHERE expdate < %i || (name='%s' && (npcid=0 || charid=0 || zoneid=0 || (npcid=%i && charid=%i && zoneid=%i)))"
,Timer::GetCurrentTime(),arglist[0],qgNpcid,qgChar id,qgZoneid), errbuf, &result);


However it means you can't have a global var 'name ' for a NPC that is 'charid=0' set to 'value1', and a player specific value 'value2'. Put it in other words, you can't have a default value. The same applies to zone, though i can think any usefull situation atm.
e.g. try targlobal a variable for a (player,npc,zone), you will delete all vars with the same name that are anyzone, any player, or anynpc, no matter if they apply to this player or not.


i suggest changing this. The deletion query would be :
DELETE FROM quest_globals WHERE expdate < %li || (name='%s' && ((npcid=0 || npcid=%i ) && ( charid=0 || charid=%i) && (zoneid=0 ||zoneid=%i)))
or even more
DELETE FROM quest_globals WHERE expdate < %li || (name='%s' && (npcid=%i ) && (charid=%i) && (zoneid=%i)))
This will preserve wildcard variables.

This will however give several variables with same name in the Embparser::Event process. But, simply by changing the query to sort results, you can apply precedence of more-specific over less-specific, saying :

database.RunQuery(query, MakeAnyLenString(&query,
"SELECT name,value FROM quest_globals WHERE (npcid=%i || npcid=0) && (charid=%i || charid=0) && (zoneid=%i || zoneid=0) && expdate >= unix_timestamp(now()) order by charid , npcid, zoneid ",
npcmob->GetNPCTypeID(),charid,zone->GetZoneID()), errbuf, &result);
if (result)
{
printf("Loading global variables for %s\n",npcmob->GetName());
while (row = mysql_fetch_row(result))
{
printf("$%s = %s\n",row[0],row[1]);
ExportVar(packagename.c_str(), row[0], row[1]);
}
mysql_free_result(result);
}

if var exists, you will get 1 or more rows, matching specific (charid, npcid, zoneid) or wildcard (0,0,0), or any combiantion. Sorting makes precedence of nnnn over 0, as in the while loop the variable is exported as many times as needed, but only the last value remains set, others will have been overriden.

The results are more conform to what i thought wildcards should be.

I'd like to know what you think.