1 registered members (Ayumi),
662
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Malfunction W1508, Can't load...
#389430
12/14/11 09:41
12/14/11 09:41
|
Joined: Jun 2010
Posts: 9 Germany, Bensheim
laci
OP
Newbie
|
OP
Newbie
Joined: Jun 2010
Posts: 9
Germany, Bensheim
|
Hi, I save a struct array with this code:
#include <acknex.h>
#include <default.c>
typedef struct TESTSTRUCT
{
char word1[30];
char word2[30];
} TESTSTRUCT;
TESTSTRUCT* test_array;
FONT* font1 = "Arial#24";
FONT* infofont = "Arial#24bi";
STRING* str1 = "text 1";
STRING* str2 = "text 2";
STRING* str3 = "text 3";
STRING* str4 = "text 4";
STRING* infostr = "Start";
TEXT* txt1 = {pos_x = 10; pos_y = 10; string (str1); font = font1; flags = SHOW;}
TEXT* txt2 = {pos_x = 10; pos_y = 50; string (str2); font = font1; flags = SHOW;}
TEXT* txt3 = {pos_x = 10; pos_y = 100; string (str3); font = font1; flags = SHOW;}
TEXT* txt4 = {pos_x = 10; pos_y = 150; string (str4); font = font1; flags = SHOW;}
TEXT* infotxt = {pos_x = 10; pos_y = 200; string (infostr); font = infofont; flags = SHOW;}
///////////////////////////////
function main()
{
var fhandle;
wait(-3);
str_cpy(infostr, "read");
test_array = (TESTSTRUCT*)sys_malloc(2 * (sizeof(TESTSTRUCT)));
// test1.txt contains 2 lines:
// abc;def
// ghi;jkl
fhandle = file_open_read("test1.txt");
// line 1
file_str_readto(fhandle, test_array[0].word1, ";", 30);
file_str_readto(fhandle, test_array[0].word2, "\n", 30);
// line 2
file_str_readto(fhandle, test_array[1].word1, ";", 30);
file_str_readto(fhandle, test_array[1].word2, "\n", 30);
str_cpy(str1, test_array[0].word1);
str_cpy(str2, test_array[0].word2);
str_cpy(str3, test_array[1].word1);
str_cpy(str4, test_array[1].word2);
file_close(fhandle);
wait(-3);
str_cpy(infostr, "save");
add_struct(test_array, 2 * (sizeof(TESTSTRUCT)));
result = game_save("test", 1, SV_STRUCT);
if (result <= 0)
{
printf("Save Error!");
}
wait(-3);
str_cpy(infostr, "reset");
str_cpy(str1, "");
str_cpy(str2, "");
str_cpy(str3, "");
str_cpy(str4, "");
str_cpy(_str(test_array[0].word1), "");
str_cpy(_str(test_array[0].word2), "");
str_cpy(_str(test_array[1].word1), "");
str_cpy(_str(test_array[1].word2), "");
wait(-3);
str_cpy(infostr, "end");
sys_exit(NULL);
}
After it I try to load with this program:
#include <acknex.h>
#include <default.c>
typedef struct TESTSTRUCT
{
char word1[30];
char word2[30];
} TESTSTRUCT;
TESTSTRUCT* test_array;
FONT* font1 = "Arial#24";
FONT* infofont = "Arial#24bi";
STRING* str1 = "text 1";
STRING* str2 = "text 2";
STRING* str3 = "text 3";
STRING* str4 = "text 4";
STRING* infostr = "Start";
TEXT* txt1 = {pos_x = 10; pos_y = 10; string (str1); font = font1; flags = SHOW;}
TEXT* txt2 = {pos_x = 10; pos_y = 50; string (str2); font = font1; flags = SHOW;}
TEXT* txt3 = {pos_x = 10; pos_y = 100; string (str3); font = font1; flags = SHOW;}
TEXT* txt4 = {pos_x = 10; pos_y = 150; string (str4); font = font1; flags = SHOW;}
TEXT* infotxt = {pos_x = 10; pos_y = 200; string (infostr); font = infofont; flags = SHOW;}
///////////////////////////////
function main()
{
wait(-3);
str_cpy(infostr, "reset");
str_cpy(str1, "");
str_cpy(str2, "");
str_cpy(str3, "");
str_cpy(str4, "");
wait(-3);
str_cpy(infostr, "load");
test_array = (TESTSTRUCT*)sys_malloc(2 * (sizeof(TESTSTRUCT)));
add_struct(test_array, 2 * (sizeof(TESTSTRUCT)));
result = game_load("test", 1);
if (result <= 0)
{
printf("Load Error!");
}
str_cpy(str1, test_array[0].word1);
str_cpy(str2, test_array[0].word2);
str_cpy(str3, test_array[1].word1);
str_cpy(str4, test_array[1].word2);
wait(-3);
str_cpy(infostr, "end");
sys_exit(NULL);
}
But I get always the Error: Malfunction W1508 Can't load test1.SAV What is wrong ?
|
|
|
Re: Malfunction W1508, Can't load...
[Re: Superku]
#389536
12/15/11 14:29
12/15/11 14:29
|
Joined: Jun 2010
Posts: 9 Germany, Bensheim
laci
OP
Newbie
|
OP
Newbie
Joined: Jun 2010
Posts: 9
Germany, Bensheim
|
Hi Superku, thx for your hint! I changed the example, and it works well. I have done two examples, one for reading ASCII CSV file, and one for reading Unicode CSV file. Here there is a different: Reading ASCII: file_str_readto(fhandle, test_array[0].word1, ";", 30); Reading Unicode: temp_str = str_create("#30"); file_str_readtow(fhandle, temp_str, ";", 30); memcpy(test_array[0].word1, temp_str, 30); The function file_str_readtow works not right, only with this work around. (I tried _str() also.) And I found out, that the Error W1508 comes, if I call the function add_struct two times. The examples read from a CSV file into a struct array, and save and load the data with game_save() and game_load(). It can be useful for somebody. Example 1 with ASCII input file:
#include <acknex.h>
#include <default.c>
typedef struct TESTSTRUCT
{
char word1[30];
char word2[30];
} TESTSTRUCT;
TESTSTRUCT* test_array;
FONT* font1 = "Arial#24";
FONT* infofont = "Arial#24bi";
STRING* str1 = "text 1";
STRING* str2 = "text 2";
STRING* str3 = "text 3";
STRING* str4 = "text 4";
STRING* infostr = "Start";
TEXT* txt1 = {pos_x = 10; pos_y = 10; string (str1); font = font1; flags = SHOW;}
TEXT* txt2 = {pos_x = 10; pos_y = 50; string (str2); font = font1; flags = SHOW;}
TEXT* txt3 = {pos_x = 10; pos_y = 100; string (str3); font = font1; flags = SHOW;}
TEXT* txt4 = {pos_x = 10; pos_y = 150; string (str4); font = font1; flags = SHOW;}
TEXT* infotxt = {pos_x = 10; pos_y = 200; string (infostr); font = infofont; flags = SHOW;}
var fhandle;
long array_size;
///////////////////////////////
function create_array()
{
str_cpy(infostr, "create array");
array_size = 2 * (sizeof(TESTSTRUCT));
test_array = (TESTSTRUCT*)sys_malloc(array_size);
if(test_array == NULL)
{
printf("sys_malloc Error!");
}
memset(test_array, 0, array_size);
add_struct(test_array, array_size);
}
function copy_array()
{
// ANSI C function !!!
memcpy(str1, test_array[0].word1, 30);
memcpy(str2, test_array[0].word2, 30);
memcpy(str3, test_array[1].word1, 30);
memcpy(str4, test_array[1].word2, 30);
}
function read_file()
{
str_cpy(infostr, "read ASCII CSV file: test1.txt");
// ASCII: test1.txt contains 2 lines:
// abc;def
// ghi;jkl
fhandle = file_open_read("test1.txt");
// line 1
file_str_readto(fhandle, test_array[0].word1, ";", 30);
file_str_readto(fhandle, test_array[0].word2, "\n", 30);
// line 2
file_str_readto(fhandle, test_array[1].word1, ";", 30);
file_str_readto(fhandle, test_array[1].word2, "\n", 30);
file_close(fhandle);
copy_array();
}
function init_content()
{
str_cpy(infostr, "init content");
// ANSI C function !!!
strcpy(test_array[0].word1, "xyz");
strcpy(test_array[0].word2, "qwe");
strcpy(test_array[1].word1, "asd");
strcpy(test_array[1].word2, "poi");
copy_array();
}
function save_array()
{
str_cpy(infostr, "save: test1.SAV");
result = game_save("test", 1, SV_STRUCT);
if (result <= 0)
{
printf("Save Error!");
}
}
function load_array()
{
str_cpy(infostr, "load: test1.SAV");
result = game_load("test", 1);
if (result <= 0)
{
printf("Load Error!");
}
copy_array();
}
function main()
{
create_array();
on_r = read_file;
on_i = init_content;
on_s = save_array;
on_l = load_array;
while (1)
{
wait(1);
}
}
Example 2 with Unicode input file:
#include <acknex.h>
#include <default.c>
typedef struct TESTSTRUCT
{
char word1[30];
char word2[30];
} TESTSTRUCT;
TESTSTRUCT* test_array;
FONT* font1 = "Arial Unicode MS#24";
FONT* infofont = "Arial#24bi";
STRING* str1 = "text 1";
STRING* str2 = "text 2";
STRING* str3 = "text 3";
STRING* str4 = "text 4";
STRING* infostr = "Start";
TEXT* txt1 = {pos_x = 10; pos_y = 10; string (str1); font = font1; flags = SHOW;}
TEXT* txt2 = {pos_x = 10; pos_y = 50; string (str2); font = font1; flags = SHOW;}
TEXT* txt3 = {pos_x = 10; pos_y = 100; string (str3); font = font1; flags = SHOW;}
TEXT* txt4 = {pos_x = 10; pos_y = 150; string (str4); font = font1; flags = SHOW;}
TEXT* infotxt = {pos_x = 10; pos_y = 200; string (infostr); font = infofont; flags = SHOW;}
var fhandle;
long array_size;
///////////////////////////////
function create_array()
{
str_cpy(infostr, "create array");
array_size = 2 * (sizeof(TESTSTRUCT));
test_array = (TESTSTRUCT*)sys_malloc(array_size);
if(test_array == NULL)
{
printf("sys_malloc Error!");
}
memset(test_array, 0, array_size);
add_struct(test_array, array_size);
}
function copy_array()
{
// ANSI C function !!!
memcpy(str1, test_array[0].word1, 30);
memcpy(str2, test_array[0].word2, 30);
memcpy(str3, test_array[1].word1, 30);
memcpy(str4, test_array[1].word2, 30);
}
function read_file()
{
STRING* temp_str;
str_cpy(infostr, "read unicode CSV file: test2.txt");
// Unicode: test2.txt contains 2 lines:
// abc;def
// ghi;jkl
fhandle = file_open_read("test2.txt");
// line 1
temp_str = str_create("#30");
file_str_readtow(fhandle, temp_str, ";", 30);
memcpy(test_array[0].word1, temp_str, 30);
temp_str = str_create("#30");
file_str_readtow(fhandle, temp_str, "\n", 30);
memcpy(test_array[0].word2, temp_str, 30);
// line 2
temp_str = str_create("#30");
file_str_readtow(fhandle, temp_str, ";", 30);
memcpy(test_array[1].word1, temp_str, 30);
temp_str = str_create("#30");
file_str_readtow(fhandle, temp_str, "\n", 30);
memcpy(test_array[1].word2, temp_str, 30);
file_close(fhandle);
copy_array();
}
function init_content()
{
STRING* temp_str;
str_cpy(infostr, "init content");
// ANSI C function !!!
strcpy(test_array[0].word1, "xyz");
strcpy(test_array[0].word2, "qwe");
strcpy(test_array[1].word1, "asd");
strcpy(test_array[1].word2, "poi");
copy_array();
}
function save_array()
{
str_cpy(infostr, "save: test2.SAV");
result = game_save("test", 2, SV_STRUCT);
if (result <= 0)
{
printf("Save Error!");
}
}
function load_array()
{
str_cpy(infostr, "load: test2.SAV");
result = game_load("test", 2);
if (result <= 0)
{
printf("Load Error!");
}
copy_array();
}
function main()
{
create_array();
on_r = read_file;
on_i = init_content;
on_s = save_array;
on_l = load_array;
while (1)
{
wait(1);
}
}
|
|
|
|