Jamiras / RATools

Script interpreter for writing achievements for retroachievements.org
MIT License
48 stars 11 forks source link

[Feature Request] Allow values which are convertible to a string to be used as values in a rich_presence_lookup lookup #481

Closed Souzooka closed 4 months ago

Souzooka commented 4 months ago

Currently, RATools mandates that all values in a lookup passed to rich_presence_lookup are strings. However, this limits the ability to programmatically generate lookups.

For example, this simple code which generates lookups for a 12-hour clock:

function CalcHours()
{
    TimeOfDayLookup = {}
    HourLookup = {}
    for i in range(0, 24 - 1)
    {
        hour = if_else(i % 12 == 0, 12, i % 12)
        HourLookup[i] = hour
        TimeOfDayLookup[i] = if_else(i < 12, "AM", "PM")
    }

    return [TimeOfDayLookup, HourLookup]
}

if HourLookup is passed to rich_presence_lookup, the error value is not a string will be raised.

This can be circumvented by transforming the dictionary again with a string conversion lookup, a la

ITOALookup = {
    0: "0", 
    1: "1", 
    2: "2", 
    3: "3", 
    4: "4", 
    5: "5", 
    6: "6", 
    7: "7", 
    8: "8", 
    9: "9", 
    10: "10", 
    11: "11", 
    12: "12", 
}

for i in HourLookup
    HourLookup[i] = ITOALookup[HourLookup[i]]

but this should be unnecessary. RATools should instead attempt to convert values to string (for int, or other types if determined applicable) and instead raise an error along the lines of value is not a string nor is convertible to string.

Jamiras commented 4 months ago

You cold use format() or string concatenation to convert the integer to a string:

HourLookup[i] = format("{0}", hour)

or

HourLookup[i] = ""+hour
Souzooka commented 4 months ago

Ah, you're correct. I forgot about format for this purpose.

Souzooka commented 4 months ago

.