3 registered members (Ayumi, Akow, AndrewAMD),
1,505
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Name of the assigned function and model
[Re: 3run]
#462348
09/22/16 22:22
09/22/16 22:22
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Yes! I got it to work! Now, next thing to go is player's transition between levels. And again I'm probably making things too complicated, while trying to think of a best way to handle this. Here is the thing: I need to spawn player at correct positions, depending on which door he entered. F.e. when player goes from ROOM 1 into ROOM 2, then he should appear at the red circle (in the ROOM 2), same for the other rooms. When player goes from ROOM 3 into ROOM 2, he should appear at the green circle. I can only think of one way of handing this right now. Saving into global variable ID of the door, at which we should appear. Something like linking doors between each other. So door 1 from ROOM 1 is linked to door 1 in ROOM 2.. door 1 from ROOM 3 is linked to door 2 in ROOM 2. But I'm afraid this will get way too complicated at the end, and I'll mess things up, especially if there are going to be a lot of levels (99 level all with doors... linking all of them by hand? ). Maybe tomorrow I'll end up with better idea, but right now need to get a sleep, plus I'm ill this days, so I feel myself not that good... Edit: yeahh, still trying to keep this forums alive with double, triple posts Best regards!
|
|
|
Re: Name of the assigned function and model
[Re: 3run]
#462349
09/22/16 22:47
09/22/16 22:47
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
Serious User
|
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
Loading only position stuff etc from a txt file in combination with level_load will ofcourse be a bit simpler to make but do keep in mind that won't allow you to save e.g. summonings or 'spawned from script/ent_created' enemies (so only pre-placed enemies). If this doesn't bother you than by all means go for it. As for you door positions, iirc you can attach an other entity in WED in entity edit/properties menu (look for something like attach or parent or such). You can than use it in script. If that doesn't work out or if you need more attachments, save the ID's in skills of the door ents. And get well soon
|
|
|
Re: Name of the assigned function and model
[Re: Reconnoiter]
#462355
09/23/16 12:12
09/23/16 12:12
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Well, I don't really need 'spawned from file' entities, I could always place then in WED, and make them appear by script, didn't quite get the 'summonings', but I'm pretty good with the way it works right now The only limitation is, that objects can not be removed/deleted from the level. That's because I save them into the list (and because all entities are pre-placed in WED, they get recreated on each level load, so I'll face empty pointer when trying to load parameters from the list.. so it's much easer just to make it passable/invisible), and write that list in it's order into the file. If I remember correctly, I read here on the forum that 'ent_next' list is always different, so I didn't use it, to keep the right order of saving/loading. Thank you, I feel a bit better today. Edit: also, I'm thinking about what would be the best way of saving/loading position/orintation of NPCs. In lots of older games, they only used to reset NPCs to their start positions (without saving anything on level change). Maybe that's the way to go? Currently, I save their positions/orientations, so when I load level back, it looks same as right before going to another level. Edit2: also, when I tried to save/load everything from a single .txt file, I faced a problem with 'file_open_write' as it removes all content from the file.. 'file_open_append' write stuff at the end. Maybe I could save the whole file content into the string, then split it to BEFORE and AFTER the room that I need to change stuff in. Then after changing, add this string with changes to the BEFORE string, and then add to it AFTER string. Or maybe I'm making things too complicated again Greets.
|
|
|
Re: Name of the assigned function and model
[Re: 3run]
#462356
09/23/16 13:16
09/23/16 13:16
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
This is how I've done it (the part with changing specific line in the string):
void save_into_file(){
STRING* read_str = ""; STRING* write_str = "";
STRING* before_str = ""; STRING* after_str = "";
var fhandle = file_open_read("map.dat");
if(fhandle == NULL){ error("File wasn't found!"); return; }
var len_var = file_length(fhandle);
file_str_readto(fhandle, read_str, ";", len_var);
file_close(fhandle);
// BEFORE string:
var start_var = str_stri(read_str, "[ROOM 2]");
str_cut(before_str, read_str, 0, start_var + 7);
// AFTER string:
var end_var = str_stri(read_str, "[ROOM 3]");
str_cut(after_str, read_str, end_var, len_var);
// get the part of the string, where we need to change stuff:
str_cut(write_str, read_str, start_var + 8, end_var - 1);
str_cpy(write_str, "THIS IS NOT THE SECOND ROOM!");
// add empty space:
str_cat(before_str, " ");
// use that empty space to move pointer to the next line:
str_setchr(before_str, str_len(before_str), 10);
// add empty space to the stuff we've changed:
str_cat(write_str, " ");
// add changes to BEFORE string:
str_cat(before_str, write_str);
// use empty space at the end to move pointer to the next line:
str_setchr(before_str, str_len(before_str), 10);
// add AFTER str (so the whole string is complete now)
str_cat(before_str, after_str);
// write this all into the file:
var fhandle = file_open_write("map.dat");
file_str_write(fhandle, before_str);
file_close(fhandle);
}
This code, changed txt file, with this: [ROOM 1] This is first room! [ROOM 2] This is second room! [ROOM 3] This is third room! [ROOM 4] This is fourth room! Into this: [ROOM 1] This is first room! [ROOM 2] THIS IS NOT THE SECOND ROOM! [ROOM 3] This is third room! [ROOM 4] This is fourth room! Maybe it may come in handy for someone. Didn't test it any farther, maybe it won't work in some situations Greets!
|
|
|
Re: Name of the assigned function and model
[Re: 3run]
#462357
09/23/16 15:17
09/23/16 15:17
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
Serious User
|
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
With summonings I mean enemies (or allies) that are 'summonend/created' by enemies. So e.g. a wolf summonend by a druid, or a soldier summonend by a captain. Its just a word that I like to use to categorize entities created by script (/ by other entities). Minor point: as for ent_next's list being different everytime; this doesn't matter if you save the unique ID of entities only when first entering the map. It shouldn't matter much if entity with ID 50 gets loaded earlier than entity with ID 1, as long as both entities are loaded with their correct ID's. This is how I've done it (the part with changing specific line in the string): , there should be an easier solution. What I would do is probably something like this (not in real code but I think you will get the idea):
while (loop through every txt line of your save file) {
1) get the current line and convert it to a lite-c string
2) use the str_parse functions to get the value of that line
3) use str_cmpni's to compare it content/description in some big nested if's to determine what to do with the value
}
Last edited by Reconnoiter; 09/23/16 15:20.
|
|
|
Re: Name of the assigned function and model
[Re: Reconnoiter]
#462368
09/24/16 07:50
09/24/16 07:50
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
Hi, I would use static memory instead of a text file. File text reading, interpreting and rebuilding is pretty slow and intrincated. Look at this:
#include <acknex.h>
#define LEVEL_COUNT 20
#define OBJECTS_MAX 10
FONT *fntArial = "Arial#20";
typedef struct OBJECT
{
var x;
var y;
var z;
var pan;
var tilt;
var roll;
// and so...
} OBJECT;
OBJECT objects[LEVEL_COUNT][OBJECTS_MAX];
void objects_save ()
{
file_save ( "saved.dat", objects, sizeof(OBJECT) * LEVEL_COUNT * OBJECTS_MAX );
}
void objects_load ()
{
if ( !file_exists ( "saved.dat" ) )
return;
long size = 0;
void *buffer = file_load ( "saved.dat", NULL, &size );
memcpy ( objects, buffer, sizeof(OBJECT) * LEVEL_COUNT * OBJECTS_MAX );
file_load ( NULL, buffer, &size );
}
void objects_zero ()
{
memset ( objects, 0, sizeof(OBJECT) * LEVEL_COUNT * OBJECTS_MAX );
}
void evnPan ()
{
var indexX = floor ( LEVEL_COUNT * mouse_pos.x / screen_size.x );
var indexY = floor ( OBJECTS_MAX * mouse_pos.y / screen_size.y );
if ( event_type == EVENT_CLICK )
objects[indexX][indexY].x += 1;
else if ( event_type == EVENT_RIGHTCLICK )
objects[indexX][indexY].x -= 1;
}
void main ()
{
video_mode = 10;
mouse_mode = 4;
enable_mouse = 2;
wait(1);
PANEL *pan = pan_create ( "", 1 );
pan->size_x = screen_size.x;
pan->size_y = screen_size.y;
var stepX = pan->size_x / LEVEL_COUNT;
var stepY = pan->size_y / OBJECTS_MAX;
var y = 0;
for ( ; y<OBJECTS_MAX; y+=1 )
{
var x = 0;
for ( ; x<LEVEL_COUNT; x+=1 )
{
pan_setdigits ( pan, 0, (stepX/2)+x*stepX, (stepY/2)+y*stepY, "%.0f", fntArial, 1, &objects[x][y].x );
}
}
pan->event = evnPan;
pan->flags |= SHOW;
on_s = objects_save;
on_l = objects_load;
on_r = objects_zero;
while ( !key_esc )
wait (1);
pan_remove ( pan );
sys_exit ( NULL );
}
mouse_left -> encrease mouse_right -> decrease R -> zero all values S -> save data L -> load data It saves and loads an array with no interpretations inbetween. Raw data is saved and loaded, so ( before) after a load everything gets arranged by the array structure you can easily access. It has other advantajes beside saving and loading like objects linking through levels. But it also have some disadvantajes like, for example, you can't save pointers with this method, so texts has to be saved into char arrays or object links have to be saved as indexes or offsets into the array. Nothing hard to manage. Salud!
Last edited by txesmi; 09/24/16 13:39.
|
|
|
Re: Name of the assigned function and model
[Re: txesmi]
#462369
09/24/16 10:36
09/24/16 10:36
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
Serious User
|
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
Good idea txesmi. That is actually somewhat similar to the idea how I do it in c# with a container class, but never realized it would be possible this way with lite-c/c. Do you know if your example can also be used to directly save entity data (pos/rotation/scale+skills and possible flags etc) without using a struct? Like maybe lite-c has already some entity struct that we could use?
Last edited by Reconnoiter; 09/24/16 10:38.
|
|
|
|