POV-Ray : Newsgroups : povray.general : problem reading text from file Server Time
2 Nov 2024 03:17:32 EDT (-0400)
  problem reading text from file (Message 1 to 4 of 4)  
From: stevenvh
Subject: problem reading text from file
Date: 20 Aug 2010 02:30:01
Message: <web.4c6e206e5ce7b402c0721a1d0@news.povray.org>
Hi,
I've got a text file I want to read from:

    "first, second, third"

I want to read the first item ("first") into Var1:

    #fopen MyFile "test.txt" read
    #read (MyFile, Var1)
    #fclose MyFile

When I run this code I get the error"

    "test.txt" line 1: Parse Error: Expected 'float, vector,
    or string literal', undeclared identifier 'first' found instead

Apparently POV-Ray interprets the first data item as an identifier. Is my
understanding of #read wrong?
TIA
Steven


Post a reply to this message

From: Warp
Subject: Re: problem reading text from file
Date: 20 Aug 2010 02:40:09
Message: <4c6e2349@news.povray.org>
stevenvh <nomail@nomail> wrote:
> Hi,
> I've got a text file I want to read from:

>     "first, second, third"

> I want to read the first item ("first") into Var1:

>     #fopen MyFile "test.txt" read
>     #read (MyFile, Var1)
>     #fclose MyFile

> When I run this code I get the error"

>     "test.txt" line 1: Parse Error: Expected 'float, vector,
>     or string literal', undeclared identifier 'first' found instead

> Apparently POV-Ray interprets the first data item as an identifier. Is my
> understanding of #read wrong?

  The #read command can only read literals of the same type as in regular
SDL files. If you want it to read a string literal, you have to put it in
quotes. In other words, your file has to contain this:

    "first", "second", "third"

  As you noticed from the error message, you could also have identifiers
in the file, but they obviously need to be declared before reading the
file for it to work. (Another less-known fact is that you can actually
have #declares and other #-commands in the file being read, and they will
be interpreted accordingly.)

-- 
                                                          - Warp


Post a reply to this message

From: stevenvh
Subject: Re: problem reading text from file
Date: 20 Aug 2010 02:45:00
Message: <web.4c6e2368485f7d95c0721a1d0@news.povray.org>
Ah, got it! It appears that I have to enclose each word in quotes.


Post a reply to this message

From: stevenvh
Subject: Re: problem reading text from file
Date: 20 Aug 2010 03:05:01
Message: <web.4c6e2833485f7d95c0721a1d0@news.povray.org>
"stevenvh" <nomail@nomail> wrote:
> Ah, got it! It appears that I have to enclose each word in quotes.

Posted before I had read Warp's reply, obviously. :-)


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.