Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 File Writing Problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Miyoko




PostPosted: Sun Apr 06, 2003 10:28 am   Post subject: File Writing Problem

For some reason when I run this
Quote:
procedure file_write ( filename : string, written_line : string )
var fileNo : int
open : fileNo, filename, write, seek
seek : fileNo, *
write : fileNo, written_line
close : fileNo
end file_write

it writes exactly what I want, but it also writes all the string variables in the program to the text file also.
Quote:
test /GUI/Menu/menu_activated.bmp newgame_single newgame_1vs1 newgame_network /GUI/Menu/menu_deactivated.bmp /GUI/Menu/menu_activated.bmp /GUI/Menu/Config/menu_black.bmp /GUI/Menu/Config/menu_keys.bmp Load player 1 setup Load player 2 setup Apply pl

When what inputed was supposed to be just "test".
Anyway, if you have any idea why it's doing this let me know. Thanks ...
~Jen
Sponsor
Sponsor
Sponsor
sponsor
Asok




PostPosted: Sun Apr 06, 2003 11:35 am   Post subject: (No subject)

it depends on where you put it. you may be writing more than you want but we can't really tell from just that procedure. Posting the remainder of the code would be helpful to debug it.
Miyoko




PostPosted: Sun Apr 06, 2003 3:57 pm   Post subject: (No subject)

It's just a procedure that gets called, looking at the code any decently made devolopment program would unset any variables after a procedure and or a function is executed. Apparently Turing 4.0.3 does not.
void




PostPosted: Sun Apr 06, 2003 4:28 pm   Post subject: i agree wit asok

If you want your program debugged the post the full thing or summin and bold the code that you think is skrewing up....that would be helpful because from what you wrote we have aboslutely no clue what your aim is in doing this program is it to open a user specified file to save to or.....? yeha...while were on the topic...do ne of u know how to create a file thru winOOT....? i tried to do it...and the computer kept giving me errors like some restrictions on MS-DOS crap shizzle so i dont know if im using the right code...how would you go about creating a file..i want to create a new file for each player that uses the game and so when they open the game it says like:
Player (textbox)
Password (textbox)
(button) load user
(button) create user
and if the click on create user i get it to run a procedure that in essence creates a new text file and writes to it....
how would you do this...and would it be easier to just write to the same file and use seek to find and create users?
thanks in advance
Miyoko




PostPosted: Mon Apr 07, 2003 12:04 am   Post subject: (No subject)

Okay here's my code for the program, I would take little snippits but you will see where it's taking all these variables from.
Quote:
/************************
* VARIABLES
************************/
var global_main_directory : string := "C:/Documents and Settings/NewSpecies/Desktop/oot/TetrisAtk" %global root directory
var global_client_key_str : string (1) := "" %Global keystr
var global_windowset : int %Global Window

var menu_end : boolean := false %Ends the menu if true
var menu_selected : int := 1 %Last deselected menu
var menu_deselected : int := 1 %Last selected menu
var menu_load_selection : string := "" %Load different new game setting or exit the game

var screenWidth : int := Config.Display (cdScreenWidth)
var screenHeight : int := Config.Display (cdScreenHeight)

var control_client_up : array 1 .. 2 of int := init(200, 200) %up
var control_client_down : array 1 .. 2 of int := init(208, 208) %Down
var control_client_left : array 1 .. 2 of int := init(203, 203) %Left
var control_client_right : array 1 .. 2 of int := init(205, 205) %Right
var control_client_drop : array 1 .. 2 of int := init(32, 32) %Space Bar
var control_client_flip : array 1 .. 2 of int := init(10, 10) %Enter Key
var control_client_tmp_keys : array 1 .. 2, 1 .. 6 of int

var control_server_up : int := 200 %up
var control_server_down : int := 208 %Down
var control_server_left : int := 203 %Left
var control_server_right : int := 205 %Right
var control_server_drop : int := 32 %Space Bar
var control_server_flip : int := 10 %Enter Key
var control_server_tmp_keys : array 1 .. 6 of int

/************************
* PROCEDURES
************************/
procedure initialize_window ()
global_windowset := Window.Open ("fullscreen")
%global_windowset := Window.Open ("position:top;center,graphics:200;200")
%Window.Set (global_windowset, "nocursor")
View.Set ("graphics:640;480")
%setscreen("graphics:640;480")
%setscreen("nocursor")
%setscreen("noecho")
%setscreen("fullscreen")
setscreen ("title:Tetris Attack!")
color (0)
colorback (255)
cls
end initialize_window

procedure deinitialize_window ()
Window.Close (global_windowset)
Music.PlayFileStop
end deinitialize_window

procedure menu_draw (menu_new, menu_old, menu_id, menu_sound : int)
case menu_id of
label 1 :
%General Menu
case menu_old of
label 0 :
label 1 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/New/Menu_Deselected.bmp", 20, 260, picCopy)
label 2 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/Config/Menu_Deselected.bmp", 20, 190, picCopy)
label 3 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/Exit/Menu_Deselected.bmp", 20, 90, picCopy)
end case
case menu_new of
label 0 :
label 1 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/New/Menu_Selected.bmp", 20, 260, picCopy)
label 2 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/Config/Menu_Selected.bmp", 20, 190, picCopy)
label 3 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/Exit/Menu_Selected.bmp", 20, 90, picCopy)
end case
label 2 :
%New Menu
case menu_old of
label 0 :
label 1 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/New/menu_single_deselected.bmp", 290, 265, picCopy)
label 2 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/New/menu_1vs1_deselected.bmp", 290, 225, picCopy)
label 3 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/New/menu_netplay_deselected.bmp", 290, 170, picCopy)
label 4 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/New/menu_back_deselected.bmp", 290, 105, picCopy)
end case
case menu_new of
label 0 :
label 1 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/New/menu_single_selected.bmp", 290, 265, picCopy)
label 2 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/New/menu_1vs1_selected.bmp", 290, 225, picCopy)
label 3 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/New/menu_netplay_selected.bmp", 290, 170, picCopy)
label 4 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/New/menu_back_selected.bmp", 290, 105, picCopy)
end case
label 3 :
%Config Menu
case menu_old of
label 0 :
label 1 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/Config/menu_player1_deselected.bmp", 375, 315, picCopy)
label 2 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/Config/menu_player2_deselected.bmp", 375, 290, picCopy)
label 3 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/Config/menu_apply_deselected.bmp", 280, 102, picCopy)
label 4 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/Config/menu_cancel_deselected.bmp", 280, 80, picCopy)
end case
case menu_new of
label 0 :
label 1 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/Config/menu_player1_selected.bmp", 375, 315, picCopy)
label 2 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/Config/menu_player2_selected.bmp", 375, 290, picCopy)
label 3 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/Config/menu_apply_selected.bmp", 280, 102, picCopy)
label 4 : Pic.ScreenLoad (global_main_directory + "/GUI/Menu/Config/menu_cancel_selected.bmp", 280, 80, picCopy)
end case
end case
if menu_sound = 1 then
Music.PlayFile (global_main_directory + "/Sounds/Menu/Move.wav")
end if
end menu_draw

procedure file_delete ( file : string )
if File.Exists(file) then
File.Delete(file)
end if
end file_delete

procedure file_write ( filename : string, written_line : string )
var fileNo : int
open : fileNo, filename, write, seek
seek : fileNo, *
write : fileNo, written_line
close : fileNo
end file_write


procedure set_client_keys ( player_id : int )
control_client_up(player_id) := control_client_tmp_keys(player_id, 1)
control_client_down(player_id) := control_client_tmp_keys(player_id, 2)
control_client_left(player_id) := control_client_tmp_keys(player_id, 3)
control_client_right(player_id) := control_client_tmp_keys(player_id, 4)
control_client_flip(player_id) := control_client_tmp_keys(player_id, 5)
control_client_drop(player_id) := control_client_tmp_keys(player_id, 6)
end set_client_keys

procedure set_server_keys ( up, down, left, right, flip, drop : int)
control_server_up := control_server_tmp_keys(1)
control_server_down := control_server_tmp_keys(2)
control_server_left := control_server_tmp_keys(3)
control_server_right := control_server_tmp_keys(4)
control_server_drop := control_server_tmp_keys(5)
control_server_flip := control_server_tmp_keys(6)
end set_server_keys

/************************
* FUNCTIONS
************************/
function key_buffer (key_old : string (1)) : string (1)
var key_buffer : string (1)
loop
if hasch = false then
result key_old
end if
getch (key_buffer)
if not key_old = key_buffer then
result key_buffer
end if
end loop
end key_buffer

function menu_submenu (sub_min, sub_max, sub_start, sub_id : int) : int
var submenu_selected : int := 1 %Last deselected menu
var submenu_deselected : int := sub_min %Last selected menu
for i : sub_min .. sub_max
if not i = sub_min then
menu_draw (1, i, sub_id, 0)
else
menu_draw (sub_min, i, sub_id, 0)
end if
end for
loop
if hasch = true then
global_client_key_str := key_buffer (global_client_key_str)
if ord (global_client_key_str) = control_client_up(1) then
submenu_deselected := submenu_selected
if not submenu_deselected = sub_min then
submenu_selected := submenu_selected - 1
menu_draw (submenu_selected, submenu_deselected, sub_id, 1)
end if
elsif ord (global_client_key_str) = control_client_down(1) then
submenu_deselected := submenu_selected
if not submenu_deselected = sub_max then
submenu_selected := submenu_selected + 1
menu_draw (submenu_selected, submenu_deselected, sub_id, 1)
end if
elsif ord (global_client_key_str) = control_client_flip(1) then
Music.PlayFile (global_main_directory + "/Sounds/Menu/Click.wav")
result submenu_selected
end if
end if
end loop
end menu_submenu

/************************
* Processes
************************/
process menu_bgmusic ()
var musicfile : int
randomize
randint(musicfile, 1, 3)
loop
exit when menu_end = true
Music.PlayFile (global_main_directory + "/Sounds/Menu/menu_bgmusic_" + intstr(musicfile) + ".mp3")
end loop
end menu_bgmusic

/************************
* MAIN EXEC
************************/
initialize_window ()
Pic.ScreenLoad (global_main_directory + "/GUI/Menu/menu_background.bmp", 0, 0, picCopy)
%menu_draw(1, 0, 1, 0)
fork menu_bgmusic
loop
file_write(global_main_directory + "/Variables/Controls.taf","test")
case menu_submenu (1, 3, 1, 1) of
label 1 :
Pic.ScreenLoad (global_main_directory + "/GUI/Menu/menu_activated.bmp", 270, 80, picCopy)
menu_end := true
case menu_submenu (1, 4, 1, 2) of
label 1 : menu_load_selection := "newgame_single"
label 2 : menu_load_selection := "newgame_1vs1"
label 3 : menu_load_selection := "newgame_network"
label 4 : menu_end := false

end case
Pic.ScreenLoad (global_main_directory + "/GUI/Menu/menu_deactivated.bmp", 270, 80, picCopy)
label 2 :
Pic.ScreenLoad (global_main_directory + "/GUI/Menu/menu_activated.bmp", 270, 80, picCopy)
loop
Pic.ScreenLoad (global_main_directory + "/GUI/Menu/Config/menu_black.bmp", 280, 130, picCopy)
Pic.ScreenLoad (global_main_directory + "/GUI/Menu/Config/menu_keys.bmp", 395, 85, picCopy)
case menu_submenu (1, 4, 1, 3) of
label 1 : put "Load player 1 setup"
label 2 : put "Load player 2 setup"
label 3 : put "Apply player 1/2 setup"
label 4 : exit
end case
end loop
Pic.ScreenLoad (global_main_directory + "/GUI/Menu/menu_deactivated.bmp", 270, 80, picCopy)
label 3 : menu_end := true
end case
exit when menu_end = true
end loop

deinitialize_window
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: