Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, TedMar, dr_panther), 1,049 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
little fileread problem #277755
07/10/09 13:54
07/10/09 13:54
Joined: Jul 2009
Posts: 15
Netherland
M
malhal Offline OP
Newbie
malhal  Offline OP
Newbie
M

Joined: Jul 2009
Posts: 15
Netherland
File read

After working for three months with 3dGamestudio I finally managed to make a nice game, however I’m still have trouble with a few very basic routines such as reading numbers from a file and store them in an array.


When I run the following lines:



var fhandle;

STRING* test_str;

function main()
{
video_mode = 7;
screen_color.blue = 150;


fhandle = file_open_read("test.txt");
file_str_read(fhandle,test_str);
file_close(fhandle);
}

I get the error: “invalid pointer or handle in a function”. I didn’t come up with this code myself but got it from the help file, it does not work however. Is this C script instead of Lite C? If this is solved, the next step would be to put the numbers in an array. Who can help me with this little fileread problem?

Re: little fileread problem [Re: malhal] #277762
07/10/09 14:26
07/10/09 14:26
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
You are mixing both languages together, that's not allowed.

Try this...

Code:
var fhandle;
STRING* test_str;

void main()
{
video_mode = 7; 
wait(1);
vec_set(screen_color,vector(150,0,0));
fhandle = file_open_read("test.txt"); 
file_str_read(fhandle,test_str); 
file_close(fhandle);
}



Re: little fileread problem [Re: DJBMASTER] #277809
07/10/09 20:04
07/10/09 20:04
Joined: Jul 2009
Posts: 15
Netherland
M
malhal Offline OP
Newbie
malhal  Offline OP
Newbie
M

Joined: Jul 2009
Posts: 15
Netherland
Thanks... but... using your code I get exactly the same error as before:
“invalid pointer or handle in a function”

could you give me a solution in Lite C?

Re: little fileread problem [Re: malhal] #277810
07/10/09 20:13
07/10/09 20:13
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
That is lite-c. That error seems to indicate that the 'fhandle' variable is invalid and therefore i guess that the file isn't opened/read properly.

Try again with a new .txt file, and make sure it is in the same directoy as your script.

Re: little fileread problem [Re: DJBMASTER] #277817
07/10/09 20:54
07/10/09 20:54
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
Do you include :

#include <acknex.h>

If not, set this Line at the top of your script. And make the lite-c Workshop...

Re: little fileread problem [Re: Widi] #277856
07/11/09 04:11
07/11/09 04:11
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
STRING* test_str = "";


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: little fileread problem [Re: EvilSOB] #277954
07/11/09 16:32
07/11/09 16:32
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
@EvilSOB: oh yeah, you are right....

Re: little fileread problem [Re: Widi] #277967
07/11/09 17:54
07/11/09 17:54
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
You needed to tour an un-initialised string pointer
into an actual string that can be filled by file_str_read.
Easy mistake.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: little fileread problem [Re: EvilSOB] #278439
07/13/09 20:52
07/13/09 20:52
Joined: Jul 2009
Posts: 15
Netherland
M
malhal Offline OP
Newbie
malhal  Offline OP
Newbie
M

Joined: Jul 2009
Posts: 15
Netherland
Ok thanks you all... it worked.

STRING* test_str = "";

is indeed necessary, but the error message I got: “invalid pointer or handle in a function” was about something else....

somehow I saved the file: test.txt as test.txt.txt, this kind of file name is allowed by Vista (strange??) but not by Lite c of course. To make simple things more complicated Vista explorer did doew not show the file extension, so I just saw test.txt, only when I made a second text file I saw my mistake.... I really feel like a beginner, thanks anyway.


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1