Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, RealSerious3D, BrainSailor), 1,265 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
trouble with my highscoorelist #117455
03/14/07 11:08
03/14/07 11:08
Joined: May 2006
Posts: 132
Norway
Fiskekona Offline OP
Member
Fiskekona  Offline OP
Member

Joined: May 2006
Posts: 132
Norway
Hi everyone!
I am struggeling now

I am trying to make a highscoorelist. Take the players name wiht inkey and save it to a txt file, then at the end of the game take the highscoore and save it to another txt file. Then open them bouth and display them at the same line.
I get the name to show but not the highscoore. I can see that it has been saved, but cant get it to show.

here is how I want it to look like:

1. petter 45678
2. line 37895

Does anyone of you have any suggestions on how to solve this. I cant see it....
Here is my codes:
Code:
var data_handle;
string playerName_str[30];

text playerName_txt

{
font = standard_font;

layer = 30;

pos_x = 300;

pos_y = 275;

string = playerName_str;

}

function add_Player()

{

playerName_txt.string = "Please enter your name.";

playerName_txt.visible = on;

sleep (3); // show the text for 3 seconds

playerName_txt.string = PlayerName_str;

str_cpy(playerName_str, ""); // reset the string

while (str_cmpi (playerName_str, "") == 1) // run this loop until the player has typed something

{

inkey (playerName_str); // store player's input in name_str

wait (1);
playerName_txt.visible = off;

}

data_handle = file_open_write("playerName.txt"); // open (or create and open) this file

file_str_write (data_handle, playerName_str); // write the name of the player to the file

file_close (data_handle);

}


function show_Player()
{

panel_main.visible = off;//close main panel
butt1.visible = off;//close button
butt2.visible = off;//close button
butt3.visible = off;//close button
butt4.visible = off;//close button
butt5.visible = off;//close button
highscoore_pan.visible = on;//open higscoore panel

var filehandle;

filehandle = file_open_read ("playerName.txt");//open the file
file_str_read (filehandle, playerName_str);//we copy the string to display_string
file_close (filehandle);//close the file
playerName_txt.visible = on;//make the text visible

}


//*******************************************//
var highscoore = 1467; //added some scoore so I can see that it is showing....
text highscoore_txt

{
font = standard_font;

layer = 31;

pos_x = 500;

pos_y = 275;
string = highscoore;


}
var scoore_temp;

function save_higscoore("save_scoore.txt")
{
scoore_temp=file_open_write("save_scoore.txt");

file_var_write(scoore_temp,highscoore);
file_close(scoore_temp);
}

function open_higscoore("save_scoore.txt")
{
panel_main.visible = off;//close main panel
butt1.visible = off;//close button
butt2.visible = off;//close button
butt3.visible = off;//close button
butt4.visible = off;//close button
butt5.visible = off;//close button
highscoore_pan.visible = on;//open higscoore panel


scoore_temp=file_open_read("save_scoore.txt");
highscoore = file_var_read(scoore_temp);
file_close(scoore_temp);
highscoore_txt.visible = on;//make the text visible
}




//******************************

Function add_to_highscoorelist()//add player name and highscoore to a txt file
{
add_Player();
save_higscoore();
}

Function show_highscoorelist()//open and shows playername and the players hihgscoore
{

show_Player();
open_higscoore();
}




Programmer in training... Own GameStudio Commerical 6.50
Re: trouble with my highscorelist [Re: Fiskekona] #117456
03/14/07 12:15
03/14/07 12:15
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
I think this is the problem:
Code:

text highscoore_txt
{
font = standard_font;
layer = 31;
pos_x = 500;
pos_y = 275;
string = highscoore; // <-- WRONG !
}



A var is a var and not a string, this are two different data types!
However you can do this:
Code:

var highscoore;

string highscoore_str; //BRAND NEW!

text highscoore_txt
{
font = standard_font;
layer = 31;
pos_x = 500;
pos_y = 275;
string = highscoore_str;
}

function open_highscoore()
{
//.. your code up to the file_var_read
highscoore = file_var_read(scoore_temp);
file_close(scoore_temp);

str_for_num(highscoore_str,highscoore); //<-- BRAND NEW!
highscoore_txt.visible = on;
}



What you do is converting the var highscoore to a string highscoore_str

Btw: highscore is written with one "o"

Re: trouble with my highscorelist [Re: Xarthor] #117457
03/14/07 13:07
03/14/07 13:07
Joined: May 2006
Posts: 132
Norway
Fiskekona Offline OP
Member
Fiskekona  Offline OP
Member

Joined: May 2006
Posts: 132
Norway
Yes that was what I am looking for. It displays the scoore as I wanted.

But how do I do it...?
I want to be able to add several player names (hopefully many want to play the game) .
As it is now, the new playername deletes the old one, the same happends with the highscore....

Can someone direct me to the right.....codes...thanks....
What I want is to be able to have a highscoore list that contains 10 playernames and scoores...

1.petter 56789
2.nins 98765
.
.
.
10.lars 12345

I am learning.....


Programmer in training... Own GameStudio Commerical 6.50
Re: trouble with my highscorelist [Re: Fiskekona] #117458
03/14/07 13:12
03/14/07 13:12
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Code:

data_handle = file_open_write("playerName.txt"); // open (or create and open) this file



Better use file_open_append

Re: trouble with my highscoorelist [Re: Fiskekona] #117459
03/17/07 12:52
03/17/07 12:52
Joined: May 2006
Posts: 132
Norway
Fiskekona Offline OP
Member
Fiskekona  Offline OP
Member

Joined: May 2006
Posts: 132
Norway
But how do I Read the txt files, so that it displays the scorelist as I want to?

1.petter 6789
2.nina 4567
.
.
10.lars 1234

I use but it only shows one name. I want to sisplay al names and show it like i showed above....
I dont have any "books" that shows me how to do this save and read things. Only learned what I know from study codes.... but have some troubles understand....
This code I use to read and show the player name. But it shows only one name, or when I use file_open_append it shows al the names after each other like this
petterninalars.... I want them to be separated and each name on a new line....how do I do that. I am greatefull for al help.
Code:
 		function show_Player() 
{
var filehandle;

filehandle = file_open_read ("playerName.txt");//open the file
file_str_read (filehandle, playerName_str);//we copy the string to display_string
file_close (filehandle);//close the file
playerName_txt.visible = on;//make the text visible

}




Programmer in training... Own GameStudio Commerical 6.50
Re: trouble with my highscoorelist [Re: Fiskekona] #117460
03/17/07 13:45
03/17/07 13:45
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Ok I would differ between the displayed highscore and the internal highscore which is sorted etc.

The displayed-highscore would be made just out of one string array aka. text object.

Example for a highscore with ten entries:
Code:

text highscore_display
{
pos_x = x;
pos_y = y;
layer = z;
font = my_font;
strings = 10;
}



The interal highscore would consist out of a string array and a numeric array:
Code:

var hs_points[10];
text hs_names { strings = 10; }



What you save on the harddisk: the point array and the name strings:
Code:

function save_highscore
{
var i = 0;
var fhandle_1;
var fhandle_2;

fhandle_1 = file_open_write("hs_points.txt");
fhandle_2 = file_open_write("hs_names.txt");
while(i < 10)
{
file_var_write(fhandle_1,hs_points[i]);
file_str_write(fhandle_2,hs_names.string[i]);
i += 1;
}
file_close(fhandle_1);
file_close(fhandle_2);
}



Loading works the same way but with file_var/str_read

Sorting the highscore:
This happens when you add a new highscore entry.
Basicly you have to compare the new entry value with the current entry values and then have to do a copying down, so that the last entry drops out of the list, or the entry does not get in, because its value is < the lowest highscore entry.
Ok, so lets do a simple function for this:
Code:

function hs_add_entry(_value,_name)
{
var i = 0;
var k = 1;

while(k)
{
if(hs_points[i] < _value || i = 9)
{
k = 0;
}
else { i+= 1; }
}
//Now we know where to place the new entry in the list
//But we first have to scroll the other entrys to the bottom
k = 9;
while(k > i)
{
hs_points[k] = hs_points[k-1];
str_cpy(hs_names.string[k],hs_names.string[k-1]);
k -= 1;
}
hs_points[i] = _value;
str_cpy(hs_names.string[i],_name);
}

//How to call the function:
hs_add_entry(var,string);

example:
hs_add_entry(999,"Fiskekona");



Ok now the displaying of the highscore:
This function will make a string out of the interal arrays and save it to that text object which you then can display:
Code:

string temp1_str;
string entry_str;

function hs_show()
{
var i = 0;
while(i < 10)
{
str_for_num(entry_str,i+1);
str_cat(entry_str,". ");
str_cat(entry_str,hs_names.string[i]);
str_for_num(temp1_str,hs_points[i]);
str_cat(entry_str," ");
str_cat(entry_str,temp1_str);

i += 1;
}
}



NOTE: None of this code has been tested by me, I wrote it all of my head how it _could_ work. No gurantee that it will.
But this should give you a slight idea how you could handle a highscore system.

Re: trouble with my highscoorelist [Re: Xarthor] #117461
03/19/07 13:22
03/19/07 13:22
Joined: May 2006
Posts: 132
Norway
Fiskekona Offline OP
Member
Fiskekona  Offline OP
Member

Joined: May 2006
Posts: 132
Norway
thanks for exsplaining and showing code. I will study it and see if I understand thanks.


Programmer in training... Own GameStudio Commerical 6.50
Re: trouble with my highscoorelist [Re: Fiskekona] #216450
07/17/08 07:05
07/17/08 07:05
Joined: Jun 2008
Posts: 91
C
Coisox Offline
Junior Member
Coisox  Offline
Junior Member
C

Joined: Jun 2008
Posts: 91
Thank you so much Xarthor! I can see it very clearly. smile Very good explaination.

Re: trouble with my highscoorelist [Re: Coisox] #216764
07/18/08 18:17
07/18/08 18:17
Joined: Jun 2008
Posts: 91
C
Coisox Offline
Junior Member
Coisox  Offline
Junior Member
C

Joined: Jun 2008
Posts: 91
Fiskekona, did you success implementing his code? I got the picture but couldn't make it happen. Mind to share with me? I use Lite-C.

Re: trouble with my highscoorelist [Re: Coisox] #217037
07/21/08 00:40
07/21/08 00:40
Joined: Dec 2005
Posts: 116
T
tD_Datura_v Offline
Member
tD_Datura_v  Offline
Member
T

Joined: Dec 2005
Posts: 116
The same task should be much easier (trivial) in Lite-C.

Many recent Lite-C snippets seem more like duplicate C-Scripts forced into a space, and twisted a bit.

In other words, although limitations in the older language might be removed in Lite-C, C-Script's ridiculous boundaries are still present in a number of freshly duped C-Script samples.

However, it's not really even notable, with absurdity so common here, and C isn't exactly bustling with sparkling new innovative flexibility anyway.

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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