forums

TNT Basic Forums > Programming Q&A
File Input problems, Jump procedure problem. Please Help!
< Last Thread     Next Thread >
Author
Thread        Post A Reply

04-28-2003 06:59

Posted by:
Freefall

Click Here to Email Freefall   Find more posts by Freefall

Ok, My first problem is trying to load a config file I have my app save in the prefs folder. I can find the file OK, but I don't know how to read the data inside it.
I have looked at the online guides, searched here etc, and can't find any good examples.
My config is a text file with 6 lines of text, which I want to read into a set of variables. I have come up with the following code for it:

****CODE****
Set Directory User Preferences
float pos = 0
int config = Open File("V2Config.cfg",false,"TEXT")
int screenmode = File Read Int (config)
pos = pos + 1
pos = File Position (config)
str Fullscreen = File Read String (config)
pos = pos + 1
pos = File Position (config)
str P1Tag = File Read String (config)
pos = pos + 1
pos = File Position (config)
str P2Tag = File Read String (config)
pos = pos + 1
pos = File Position (config)
int gSpeed = File Read Int (config)
pos = pos + 1
pos = File Position (config)
str displayFPS = File Read String (config)

if screenmode = 0
sw = 640
sh = 480
end if
...(etc etc for all 6 screen modes that are supported)

It doesn't copy any of the data from the file into the variables, and then gives me an unexpected EOF error on line 7.
How are you supposed to use the file I/O?

Secondly, I have the following code for testing if someone is trying to jump or not and then if so to make it jump.

****CODE****

global int isJumping = 0, upVel = 0 'isJumping = 0 if hes not jumping, 1 if he is. upVel = the up speed.
global float w1Y = 70 'w1Y is Player 1's Y pos

if Pressed(49) and isJumping = 0
Jump()
upVel = -8
end if

Procedure Jump()
while upVel <= 0 and upVel >= (-8)
isJumping = 1
w1Y = w1Y + upVel
upVel = upVel + 2
wend
isJumping = 0
End Proc

This does nothing. I press space, my player just sits there. I don't need anything in the jump proc to make the guy come down again, as I already have a gravity engine, which will kick in when he stops rising and make him fall down again.
Whats going on? What have I done wrong?

04-28-2003 09:22

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

I actually lost much time to understand my errors in the file input-output:
Are you sure it' s possible to do text files in TNT?
I didn' t try much, but it happened I could only make "Data" files.

are you sure the prefs file your program makes is actually a text file? Can you open it with a text editor? Are you sure there are written the variables you want to read?

04-28-2003 13:54

Posted by:
Machi

Click Here to Email Machi   Find more posts by Machi

File trouble.

You haven't declared the file "format" properly. You have only included three parameters in the open statement

int config = Open File("V2Config.cfg",false,"TEXT")

... and because you haven't specified a format, TNT assumes the file type is "data"

your code should actually be ...

int config = Open File("V2Config.cfg",false,"TEXT","text")

I have also had an intermittent error that has meant that sometimes a text file that doesn't have a .txt extension (as yours has a .cfg extension for example), will only read a certain number of characters before hitting the EOF.

I have reported this to the TNT guys but have been unable to re-create it, so they haven't really been able to action it as a bug (although I'm sure it's in there somewhere, just waiting to bite me again).

04-28-2003 14:10

Posted by:
Machi

Click Here to Email Machi   Find more posts by Machi

Jumping trouble.

It's always a little difficult to comment upon chunks of code like this without seeing what else you are doing in the program, but assuming that your program is just what you have put here, I have a couple of comments.

1) Execution is just going to charge right past your "if" statement unless it is lucky enough to pick up the key press at the instant that it checks that particular line for execution. Do you see what I mean ? You really need to look at using something like a "while" for flow control that will create a loop during which the key press can be checked more than once.

2) While procedures are a good thing, and I would encourage the use of them within TNT, your procedure here just sort of lies across the path of the execution without ever being properly called. Even a little program like this one should have a structure that ensures that YOU know exactly when the program is starting, stopping and checking for stuff. TNT programs are procedural, rather than object oriented, and a well defined structure is really important. Although others might well say stuff like - "Hey, I wrote my game of 2000 lines without those procedures and lived to tell the tale." - good structure really makes the difference between spending your time enjoyably creating and spending all of your time dismally de-bugging, again ....... and again.

04-28-2003 17:27

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

Hey, I wrote my game of 2000 lines without those procedures and lived to tell the tale!

After 4 months I understood how they are terribly usefull, but, really, if you are still getting used to the basics, there is usually not much point in putting them, they might confound you more than you are already.

04-29-2003 05:00

Posted by:
Freefall

Click Here to Email Freefall   Find more posts by Freefall

Well, I have fixed the file input problem, and it now works OK.
However the jump procedure doesnt work. I know its getting called, because the following code:

if Pressed(49) and isJumping = 0
upVel = -8
Jump()
end if
...
Procedure Jump()
while upVel <= 0 and upVel >= (-8)
print "He's Jumping!"
wend
End Proc

will print "He's jumping" to the console, however if I replace print "He's Jumping!" with:
isJumping = 1
w1Y = w1Y + upVel
upVel = upVel + 2
Then nothing happens. That obviously means that the problem is in the vit of code telling the players y position to increase.

04-29-2003 05:12

Posted by:
Freefall

Click Here to Email Freefall   Find more posts by Freefall

Sorry posted to soon. I can now make my player move up. However, using the upVel bit didnt work, so I changed it. Now, he will go up at about 5 px/sec whenever the space bar is held down.
Now, I can get a nice jump animation by specifying the exact co-ordinates to move the player to, but that means that whenever it jumps, regardless of where he is, he will always be teleported to the area I have specified.
Can someone give me a code example of how to dynamically increase the players position? For some reason in mine, the jump procedure fires the entire time the space bar is held down, even though its been told not to.

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.