Error running script: Error compiling expression - CompareElement: Operation 'LessThan' is not defined for types 'String' and 'Int32'

okay, have been coding this for around a year and for some reason something that seems like it should work isn't..

have a script that checks about the weight of a person on a scale of -5 to +5 saved as an int attribute on the player called fatness
(Thus player.fatness is what will be checked)

the Script I have is

if (player.fatness < -2) {
MSG ("Mmmhmm.. yeah your improving, still room to go though")

it seems like it would be the simpliest expression in the world but i keep getting the

Error running script: Error compiling expression 'player.fatness < -2': CompareElement: Operation 'LessThan' is not defined for types 'String' and 'Int32'
Thank you for any help, this seems simple but can't figure out whats wrong


Have you assigned a value to player.fatness???
If not, quest thinks it is a string...
(I get this so much that it is not funny!!!)
Or... did you say player.Fatness=0 earlier???
(Done that one too many times too!)


set up the value on a player as an attribute- integer and left it at the default of 0(it can be changed at the start for testing(From any number in the range) and that seems to work fine according to the debugger, until i call on a script to evaluate it the targeted goal


What you did does not work for me either...
(could be a "bug" or a "feature" of Quest we (or I) does not understand...)
I think Quest is still trying to identify the attribute as a string variable.
But...
Try this, instead of setting up player attributes, just create the variables manually in the game start:

or:
Objects
game
Start script
Set variable player.fatness = expression 0


Looks like fatness has been assigned a value, but it is a string. Did you set it to "0" instead of 0? If it is set on the Attributes tab, it should say integer, rather than string.


Yes, It is registered as a Int...however... this is the odd thing, after recreating the attribute nothing changed however when i forced it to start at the test level rather than have it modified from game play it did work.. which seems really strange because i just clicked the starting number down 4 digits on the GUI.

Might have narrowed it down, could it be the setting function i'm using? when i properly do it through game interations rather than letting the player set their starting number it works, This it doesn't seem like it would be the course but the code i use for setting it is

get input {
player.fatness = result
msg ("Your fatness level is " + player.fatness)
}

EDIT- Thanks to the jogging of the thought i realized the mistake, Input makes it into a string, so was about to fix it with using the ToInt function i think


EDIT- Thanks to the jogging of the thought i realized the mistake, Input makes it into a string, so was about to fix it with using the ToInt function i think

Right, but don't forget to check result with IsInt() that it really is a number


did you fix this issue?

if not... this should be a problem too (if it's not already fixed or never existed in your game: you just typo'ed in your post):

if (player.fatness < -2) {

needs to be this:

if (player.fatness <= 2) {


Yes, fixed it the problem was actually the setting script I had used had "Get input" that changed the attribute from a int to a string, once i realized i had to convert it back to an int it worked fine


ah okay, glad you got the issue solved.

ya, any typed-in input is by default taken as a string, so if you want it to be seen as an amount (a number: an Integer:non-decimal/Double:decimal Value), then you got to convert it, via the 'ToInt/ToDouble' Functions.

There's also the 'IsNumeric', 'IsInt', and 'IsDouble' to check the Value of your VARIABLE/input/whatever

and you can change an Integer/Double Value back-to or to a String Value, via: the 'ToString' Function

also, there's the 'GetInt', 'GetDouble', etc, which returns 'false' if it fails (including if it's a data/attribute type mismatch), which thus can be used for checking instead of the 'IsInt', 'IsDouble', 'IsNmeric', etc Functions, though do be aware that there's many ways for it to fail, which you may not want to be dealing with, and thus using the 'IsInt', 'IsDouble', 'IsNumeric', etc is more useful.


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

Support

Forums