intfiction.org

The Interactive Fiction Community Forum
It is currently Tue Nov 20, 2018 9:47 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 31 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
PostPosted: Sun Sep 09, 2018 5:19 pm 
Offline

Joined: Fri Feb 04, 2011 3:20 pm
Posts: 38
So I've encountered a bit of a confusing situation here, and have found nothing in the manual to help with either of these questions.
The scenario: The player can pan or mine for gold, and the gold has a cash value of $20/ounce (the approximate value of gold circa 1850) I simply need to allow the player to check how much gold or cash he has (and also intend to show both in the status bar -- after I get to that section of the manual)

First one:
Code:
Gold-score is a real number that varies. Gold-score is 0.16.
Cash-score is a real number that varies. Cash-score is 20 times gold-score.

However, upon compiling, Inform complains:
"Problem. The sentence 'Cash-score is 20 times gold-score' tells me that 'Cash-score', which is a real number that varies, should start out with the value '20 times gold-score', but this is an object and not a real number." .... (I get the same complaint whether I write "Gold-score" or "gold-score," so it's not about capitalization)
I had JUST defined "gold-score" as a real number, so why is Inform thinking it's an object?
That is quite confusing, because I tried a "work-around" for that in another section:
Code:
Requesting the cash held is an action out of world. Understand "cash" as requesting the cash held.
Report requesting the cash held:
   Say "The cash value of your gold is $[gold-score times 20 to 2 decimal places]."

Which works just fine.

And that brings me to my second question: Is there a way to FORCE numerical display to use a specified number of decimal places?
For instance, in the example as shown so far, the player has 0.16oz of gold. That times $20 per ounce is $3.20. However, when I try to display the amount of cash, it only shown $3.2 ..... without including the final zero to show $3.20.
You can also use the "gold" command to show the amount of gold collected thus far, and that has the same problem.
Here's the full code for both bits:
Code:
Requesting the gold held is an action out of world. Understand "gold" as requesting the gold held.
Report requesting the gold held:
   Say "So far you have amassed [gold-score to 2 decimal places] ounces of gold."

Requesting the cash held is an action out of world. Understand "cash" as requesting the cash held.
Report requesting the cash held:
   Say "The cash value of your gold is $[gold-score times 20 to 2 decimal places]."

I have read through the chapter "Numbers and Equations" in "Writing With Inform" several times, but can find nothing to help with this.
Perhaps I need to define each with units or notation? But as I understand, you can't do math with mixed units/notations in Inform. I actually tried fiddling with that as well, but got nowhere fast.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sun Sep 09, 2018 5:47 pm 
Offline
User avatar

Joined: Sun May 21, 2017 4:59 pm
Posts: 299
Location: Michigan
Well, for the first part, I find it works if I take care of it in the "When play begins" block:

Code:
The library is a room. "[Gold-score] | [Cash-score]".

Gold-score is a real number that varies.
Cash-score is a real number that varies.

When play begins:
   Now Gold-score is 0.16;
   Now Cash-score is 20.00 times gold-score.



Sample Output:

Code:
Testing
An Interactive Fiction by "Phillip J Rhoades" The story headline is "A testbed"
Release 1 / Serial number 180909 / Inform 7 build 6M62 (I6/v6.33 lib 6/12N) SD

library
0.16 | 3.2

>

_________________
~~~
My ebooks on Amazon
My ebooks on Smashwords


Last edited by howtophil on Sun Sep 09, 2018 5:50 pm, edited 1 time in total.

Top
 Profile Send private message  
Reply with quote  
PostPosted: Sun Sep 09, 2018 5:49 pm 
Offline

Joined: Fri Feb 04, 2011 3:20 pm
Posts: 38
howtophil wrote:
Well, for the first part, I find it works if I take care of it in the "When play begins" block:

Code:
The library is a room. "[Gold-score] | [Cash-score to 3 decimal places]".

Gold-score is a real number that varies.
Cash-score is a real number that varies.

When play begins:
   Now Gold-score is 0.16;
   Now Cash-score is 20.00 times gold-score.



Sample Output:

Code:
Testing
An Interactive Fiction by "Phillip J Rhoades" The story headline is "A testbed"
Release 1 / Serial number 180909 / Inform 7 build 6M62 (I6/v6.33 lib 6/12N) SD

library
0.16 | 3.2

>

What the heck? o.O
Okay, that seems weird to me. I guess tho, if it works, it works. I guess I just do the calculation in-place, wherever I need it :D


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sun Sep 09, 2018 6:02 pm 
Offline

Joined: Tue Mar 09, 2010 2:34 pm
Posts: 5407
Location: Burlington, VT
If cash-score is always 20 times gold-score, I think this should work:

Code:
To decide which real number is cash-score: decide on 20 times gold-score.


(I think the underlying issue is that when you're setting the initial value of something at compile-time, you have to set it using only literal numbers, not calculations involving other things defined at compile-time. I once had something where I defined "grid size" as a constant and I wanted another constant set to grid size squared, and it didn't work.)

For the second part, I think you can force trailing zeroes by defining money as a unit, which will also allow you to automatically put a $ in front of any monetary amount--see §15.14 of Writing with Inform.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sun Sep 09, 2018 6:48 pm 
Offline

Joined: Fri Feb 04, 2011 3:20 pm
Posts: 38
matt w wrote:
If cash-score is always 20 times gold-score, I think this should work:

Code:
To decide which real number is cash-score: decide on 20 times gold-score.


(I think the underlying issue is that when you're setting the initial value of something at compile-time, you have to set it using only literal numbers, not calculations involving other things defined at compile-time. I once had something where I defined "grid size" as a constant and I wanted another constant set to grid size squared, and it didn't work.)

For the second part, I think you can force trailing zeroes by defining money as a unit, which will also allow you to automatically put a $ in front of any monetary amount--see §15.14 of Writing with Inform.

Okay, yeah. Setting up cash-score with units does indeed force all decimal places to be shown. I had to do it like this:
Code:
Cash-value is a kind of value. $9.99 specifies a cash-value.
The Cash-score is a cash-value that varies.


That other bit tho I can't get to work. The "To decide ..."
I ended up trying it this way:
Code:
To decide which cash-value is cash-score:
   Decide on $20.00 times gold-score.

But it always prints the cash-score as $0.00 then.
My brain is in pretzels. I think I need to give this up for today and approach it with a fresh mind tomorrow. This is very frustrating. <sigh>


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sun Sep 09, 2018 6:56 pm 
Offline

Joined: Tue Mar 09, 2010 2:34 pm
Posts: 5407
Location: Burlington, VT
I think the problem is if you have both "The Cash-score is a cash-value that varies." and the "To decide which cash-value is cash-score:" phrase. The first one setts up a global variable called "cash-score" which gets set to the default value of $0.00, and the second one sets up a function call (or something) called "cash-value' which calculates it based on gold-score. But then every time you refer back to "cash-score" it checks the global variable and ignores the "to decide" phrase.

tl;dr: delete "The Cash-score is a cash-value that varies." and see if that fixes the problem.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sun Sep 09, 2018 7:09 pm 
Offline

Joined: Fri Feb 04, 2011 3:20 pm
Posts: 38
Well .... Wow ....... I don't even know WHAT to say about the outcome here.
Code:
To decide which cash-value is cash-score:
   Decide on $20.00 times gold-score.

result?
Code:
>gold
So far you have amassed 0.16 ounces of gold.

>cash
The total value of your gold is $11345592.32

uhhhh ........ WTAF o.O


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sun Sep 09, 2018 7:45 pm 
Offline

Joined: Tue Mar 09, 2010 2:34 pm
Posts: 5407
Location: Burlington, VT
Aw nuts. That looks like something related to this bug, where some real-number arithmetic is getting performed using integer operations.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sun Sep 09, 2018 8:23 pm 
Offline

Joined: Tue Mar 09, 2010 2:34 pm
Posts: 5407
Location: Burlington, VT
Reported as a bug.

So you could go back to the old workaround, but with a routine that prints an extra zero at the end of $3.20 when needed. (This took a lot of banging on to get to work, and it still might not work.)

Code:
Lab is a room.

Gold-score is a real number that varies. Gold-score is 0.16.

Requesting the gold held is an action out of world. Understand "gold" as requesting the gold held.
Report requesting the gold held:
   Say "So far you have amassed [gold-score] ounces of gold."

Requesting the cash held is an action out of world. Understand "cash" as requesting the cash held.
Report requesting the cash held:
   Say "The cash value of your gold is [cash-score as a dollar amount]."

To decide which real number is cash-score:
   Decide on gold-score times 20.

To say (amount - a real number) as a dollar amount:
   let amount-cents be the remainder after dividing (amount times 100) by 100 to the nearest whole number; [should be divisible by 10 whenever the amount needs a trailing zero. Note that something like 4.0 gets printed with one trailing zero]
   say "$";
   say amount to two decimal places;
   if the remainder after dividing amount-cents by 10 is 0:
      say "0".
   


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sun Sep 09, 2018 8:34 pm 
Offline

Joined: Fri Feb 04, 2011 3:20 pm
Posts: 38
Well ...... It's good to know it's a known bug, and I'm not actually just insane LOL
I'll give your "To say as a dollar amount" solution a try. It could work well enough.
Or I could just totally ditch the whole cash conversion and let everything be payed for with raw gold. It IS in a gold mining town, after all. ;)


Top
 Profile Send private message  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 31 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group