Quick Text Processor Question :)

Anonynn
30 Aug 2018, 02:14

I was wondering if this...

ToDouble(player.height)>= 4.0

can be put into the text processor. Would it be something like...

{ToDouble(player.height)>=4.0:}

Thanks for your help in advance!

Anonynn.


Dcoder
30 Aug 2018, 05:30

The only way I could get that to work was like this:

player.height = ToDouble(ToString(player.height))
msg ("{if player.height>=4.0:Bigger!}")

I had to first make player.height a double attribute outside of the text processor (the ToDouble function only partially worked inside the text processor). Also, I could not convert an integer attribute into a double attribute directly -- I had to first convert it to a string as an intermediate step.


Anonynn
30 Aug 2018, 05:35

Yeah, height works weird in my game.

This script...

{if player.height>=5.0:} 

^ throws a blank in the script. Are you saying I need this...

player.height = ToDouble(ToString(player.height))

before scripts that deal with the height?

Anonynn.


Dcoder
30 Aug 2018, 05:51

Yes, but you should only need to convert player.height to a double attribute once. What if you just set player.height to be a double attribute under the player's Attributes tab?


Dcoder
30 Aug 2018, 06:18

You know, the online version of Quest doesn't even see double attributes (they'll be converted to integers). So how about using two integer attributes for height -- one for feet and one for inches? Admittedly, it will then be harder to compare two different heights. You'll have to compare feet first, and if they are the same, compare inches next.


Anonynn
30 Aug 2018, 06:46

I do it even more simple that. I'm just using a string and an integer. 5.0, 5.2 <-- are single string attributes.

player.height = GetHeight()

^ this is the changed script for the string. Should I just add that code above it then? Like this...

player.height = ToDouble(ToString(player.height))
player.height = GetHeight()

Anonynn.


hegemonkhan
30 Aug 2018, 06:58

you probably should have multiple Attributes as you don't want to have possible screw ups in converting them (or if got some coding understanding, within the scripting you do the conversions and undo the conversions, as that way you don't have to have multiple Attributes, not sure which method is actually more efficient, as well as it depends on your game design and scale):

player.height_string = "5.8" // String Attribute
player.height_double = 5.8 // Double Attribute

player.height_integer = 6 // or: 5 // (depends on how you want it to be rounded) // Integer Attribute
// or multiple Integer Attributes for its digits column placements:
player.height_integer_ones_column = 5
player.height_integer_tenths_column = 8


Dcoder
30 Aug 2018, 07:04

Add my code AFTER your GetHeight changed script. And it can just be...

player.height = ToDouble(player.height)

...since it's already a string. Actually, I think you only need one line:

(This code was wrong)

What is GetHeight()? Is that a function?


Anonynn
30 Aug 2018, 07:16

Yup, that's a function :D

@HK

I think it was originally set up as just a string but it wasn't working properly so it had to be converted to a function and a double and and changed script xD

Anonynn.


Dcoder
30 Aug 2018, 07:20

I see, GetHeight is your function that runs within player.changedheight. Then ignore my previous post! Just put...

player.height = ToDouble(player.height)

somewhere AFTER you generate player.height, but BEFORE you make a comparison.


Anonynn
30 Aug 2018, 07:31

Yeah, I think that fixed it! I really appreciate your time with this. And you too HK! Thank you both so much ^_^

Anonynn.


Anonynn
30 Aug 2018, 07:33

Now I just need to figure out why something else isn't working properly x_X


Dcoder
30 Aug 2018, 07:37

The pain and addiction never end : )


The Pixie
30 Aug 2018, 09:15

You know, the online version of Quest doesn't even see double attributes (they'll be converted to integers).

What? Works for me.


mrangel
30 Aug 2018, 09:58

If you want to use functions in the text processor, use either.
{either ToDouble(player.height)>4.0:Congratulations, you're not short!|}

Because {if has a horribly long, inefficient chunk of code to compare two values, but {either just evals the condition and expects to get a boolean, so can handle whatever functions you want to give it as long as they don't contain a colon.


Dcoder
02 Sept 2018, 08:00

You know, the online version of Quest doesn't even see double attributes (they'll be converted to integers).

What? Works for me.

Doubles didn't work in the web version of 5.7.2. You might recall that caused an issue with my map demo game, forcing players to download the game instead of playing it online. I guess doubles now work in 5.8?


mrangel
02 Sept 2018, 09:31

Doubles didn't work in the web version of 5.7.2.

They work.
However, the locale is set to a European on the server for some reason. So when you type somestring + somedouble it uses a comma as the decimal separator. For example, the expression ("" + 0.5) gives the string "0,5".

This is fine, and most people might not notice unless you're doing something dumb like:

JS.eval ("somefunction(" + doublevar + ")")

That should be:

JS.somefunction (doublevar)

If you really have to interpolate Quest variables into javascript code (Note: if you have to do this, there's probably something messed up in your underlying design) you can force them to behave properly by explicitly calling ToString(doublevar).

(the JS function-call shortcut works pretty well. But it doesn't support dictionaries (only stringdictionaries, last time I checked). I have no idea why)


Dcoder
03 Sept 2018, 07:51

Thank you for the explanation.


Dcoder
21 Sept 2018, 16:15

If you want to convert a double to an integer, ToInt(game.DoubleVar) should work, but it doesn't.

Instead, you have to do ToInt(ToString(game.DoubleVar)). But, online, that causes the decimals to be replaced by commas.

So instead, you have to do...

game.IntVar= ToString(game.DoubleVar)
game.IntVar= ToInt(Replace(game.IntVar, ",", "."))

...which is a lot of code for something simple. My 2 cents.


The Pixie
21 Sept 2018, 20:18

You can use cast. It looks like this:

 cast(4.56, int)

mrangel
21 Sept 2018, 22:20

But, online, that causes the decimals to be replaced by commas.

That doesn't appear to be the case; certainly not for me.

"Here is a string with a double (" + 1.35 + ") in the middle of it" (implicit conversion) gives a string with a comma in on the web player.

But using ToString() on a double gives a correct string with a decimal point in


Dcoder
24 Sept 2018, 07:18

I'm not sure exactly where the comma problem is, but I'm now using the "cast" function to interconvert between integers and doubles. Thank you!