Skip to content

Commit 198c8b1

Browse files
demos: space-shooter: Fix high score saving (#217)
Signed-off-by: Marek Maškarinec <marek@mrms.cz>
1 parent 1cc226d commit 198c8b1

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

demos/space-shooter/enemy.um

+7-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,13 @@ fn handle*() {
7373
if global::hp == 0 {
7474
if global::score > global::hi {
7575
global::hi = global::score
76-
f := std::fopen("score", "w").item0
77-
fprintf(f, "%d", global::hi)
78-
std::fclose(f)
76+
f, err := std::fopen(th::convPath("data://score"), "w")
77+
if err.code != 0 {
78+
printf("Error: Could not write high score\n")
79+
} else {
80+
fprintf(f, "%d", global::hi)
81+
std::fclose(f)
82+
}
7983
}
8084

8185
enemies = []Enemy{}

demos/space-shooter/main.um

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ fn init*() {
2626
sound::init()
2727
global::hp = 10
2828

29-
f, err := std::fopen("score", "r")
30-
if err.code != 0 {
29+
f, err := std::fopen(th::convPath("data://score"), "r")
30+
if err.code == 0 {
3131
fscanf(f, "%d", &global::hi)
3232
std::fclose(f)
3333
}

demos/space-shooter/score

-1
This file was deleted.

umka/th.um

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ var (
392392

393393
fn umth_conv_path(path: str): str
394394
//~~fn convPath
395-
// Expands the path to a platform specific path.
395+
// Evaluate path prefixes and return as a platform native path.
396396
fn convPath*(path: str): str {
397397
//~~
398398
return umth_conv_path(path)

0 commit comments

Comments
 (0)