error: unrecognised type

Gng

hey all.
I got a strange error that says

Error running script: Error evaluating expression 'TypeOf(value) = "int" and attr = "money" and HasString(game, "moneyformat")': Specified argument was out of the range of valid values.Parameter name: Unrecognised type 'System.Decimal'

what could be the reason that I get this error?
I tested the codes separately to see where the problem was, and the code worked, but when I add them all together I get the aforementioned error.
Also, I don't have any "money" attribute so I can't figure out why it says " attr="money" "


Gng

I solved the problem:
It was that my dictionary didn't have any entries.
But still, the error's message is so unrelated

does anyone know what the message means?


Gng

It seems that also trying to round an integer number (like: Round(Int)) would also give this error but when I turn the number into double (by multiplying it with 1.0) would fix it


First of all, I dunno, lol, but I always like to try to help since I do learn something in the process as well.

Your question is hard to search on forum or quest documentation so I used Ip Man's Microsoft copilot instead, copilot can be a hit or miss as it is done by an automated bot, not a human, so take the answer with a grain of salt.

The error message you encountered is related to attribute arguments in your code. Let’s break it down:

  1. Error Message:
    Error running script: Error evaluating expression 'TypeOf(value) = "int" and attr = "money" and HasString(game, "moneyformat")': Specified argument was out of the range of valid values. Parameter name: Unrecognised type 'System.Decimal'

  2. Explanation:
    The error occurs when you’re using an attribute with an argument that doesn’t meet the expected criteria.
    Specifically, it’s complaining about the type of the argument you’re passing.

  3. Attribute Arguments:
    In your code, you have an attribute with the following expression:
    TypeOf(value) = "int" and attr = "money" and HasString(game, "moneyformat")
    This expression is used as an argument for an attribute (probably something like [SomeAttribute(...)]).

  4. Issues in the Expression:
    The error message points out that the type ‘System.Decimal’ is unrecognized. This means that the expression you’re using doesn’t match the expected types for attribute arguments.
    The expression seems to be checking whether value is of type “int,” whether attr is equal to “money,” and whether the game has a string called “moneyformat.”

  5. Potential Causes:
    The issue might be related to the way you’re using TypeOf(value) = "int". Attribute arguments typically expect constant expressions, and this dynamic check might not be allowed.
    The “unrecognized type” error could be due to the combination of conditions or the specific types involved.

  6. Solution:
    To fix this, consider using constant values for attribute arguments.
    If you need dynamic behavior, you might need to rethink your approach or find an alternative way to achieve the desired functionality.

  7. Rounding Issue:
    You mentioned that rounding an integer number using Round(Int) also caused a similar error.
    Converting the number to a double (by multiplying with 1.0) resolved the issue. This suggests that the attribute argument expects a specific type (like a double) rather than an integer.

In summary, review the attribute usage in your code, ensure that the arguments are constant expressions, and verify the expected types. If you encounter similar issues, consider alternative approaches or consult the documentation for the specific attribute you’re using. 🤖👍


Gng

Thank you for your answer
I also searched about it but came with no answers. I think I'm the first one to encounter this error. Hopefully this helps other quest creators if they encounter this problem:

I was able to solve the problem by changing the attribute from int to double.
for example:
player.health = etc.
player.health = player.health * 1.0
player.health = Round(player.health)

It's because I didn't want to have decimal numbers, but sometimes the attribute doesn't have any, so trying to Round(int) it would cause an error.


Gng

Thank you for your answer
I also searched about it but came with no answers. I think I'm the first one to encounter this error. Hopefully this helps other quest creators if they encounter this problem:

I was able to solve the problem by changing the attribute from int to double.
for example:
player.health = etc.
player.health = player.health * 1.0
player.health = Round(player.health)

It's because I didn't want to have decimal numbers, but sometimes the attribute doesn't have any, so trying to Round(int) it would cause an error.


That seems a little confusing. I can't figure out where System.Decimal is coming from in that.

I would expect calling Round on an int to give an error, because most of the built in functions are strongly typed; but the error mesage you quoted doesn't seem to relate to that.


Gng

Yes, it was hella confusing.
It took me a while to see where the problem was.
Hopefully, if anyone else encounters this problem, they'll find the solution on this forum.


Gng

yeah


This reminds me of Pixie's ShopLib

It's a handy little library for adding stores to your games, but you have to set a specific moneyformat for it to work without throwing an error.

It's easy to forget when you start building a new game using that library and then you have to go searching the documentation for where he tells you how and what to update it for.

I'm still learning, so is what you're saying above something like your moneyformat did or didn't have decimals, and the round function expected the opposite?


Gng

I've heard about that library but I'm not using it in my game.

There's no moneyformat in my game. The error was caused by trying to Round an attribute with int format instead of double.
Round function only works when the attribute type is double even if it doesn't have decimals.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums