Jump to content


Photo

Loading level situation


  • Please log in to reply
8 replies to this topic

#1 Misu

Misu

    Awesometasticness!

  • GMC Member
  • 435 posts
  • Version:GM:Studio

Posted 21 April 2012 - 07:27 PM

Hello GMC ! I’m not quite sure if this topic is acceptable in this forum page but in case I made a mistake, please do change it into the Novice & Intermediate Q&A.

I’m having a hard time trying to load a level from a file, which was created within the game. The loading the level code is working very well.
The levels (or strings if I can call them) are a group of file directory, which is obtain by a script when it is executed from the left mouse pressed event of an object:
//I used text format as a demonstration.
global.lvl0=get_open_filename("text (.txt)|*.txt",".txt");
global.lvl1=get_open_filename("text (.txt)|*.txt",".txt");
global.lvl2=get_open_filename("text (.txt)|*.txt",".txt");
global.lvl3=get_open_filename("text (.txt)|*.txt",".txt");
global.lvl4=get_open_filename("text (.txt)|*.txt",".txt");
Now first, I make a script for either saving all these strings in one (which is working well) or loading the group of strings from the file (which is not working right):
//I use my own file format in this one. scr_lvl_temp(Boolean)
//the Boolean is for checking wether load or save.
if 1==argument0{
ini_open("5169369122.XbbY")
global.lvl0=ini_read_string("level","type0","")
global.lvl1=ini_read_string("level","type1","")
global.lvl2=ini_read_string("level","type2","")
global.lvl3=ini_read_string("level","type3","")
global.lvl4=ini_read_string("level","type4","")
ini_close()}
if 0==argument0{ini_open("5169369122.XbbY")
ini_write_string("level","type0",global.lvl0)
ini_write_string("level","type1",global.lvl1)
ini_write_string("level","type2",global.lvl2)
ini_write_string("level","type3",global.lvl3)
ini_write_string("level","type4",global.lvl4)
ini_close()}
This code is executed at the room creation. At first it loads the first string, but when I press the “Enter key”, this should cause to skip to the next text, but instead, it didn’t load it. I try debugging and notice that the code is not loading the strings. I tried a different method by checking whether the global.lvl0==0 in step event, then it should open up the first script (to load the strings). And for draw event, it draws a text to see if global.lvl0 (and others) do not equal 0. The final result was that it did load the string but did not display the level (level didn’t loaded). I just don't get it; it should work.
Is there some way to solve this problem?

Edited by MisuMen49, 26 April 2012 - 08:54 PM.

  • 0

#2 lump

lump

    GMC Member

  • GMC Member
  • 64 posts
  • Version:GM8

Posted 21 April 2012 - 08:44 PM

about posting it in the right forum, it should be fine, i do it myself sometimes.

now onto the real topic,Can you post the contents of a typical ini file so i can see whats wrong?
  • 0

#3 Misu

Misu

    Awesometasticness!

  • GMC Member
  • 435 posts
  • Version:GM:Studio

Posted 21 April 2012 - 11:29 PM

about posting it in the right forum, it should be fine, i do it myself sometimes.

now onto the real topic,Can you post the contents of a typical ini file so i can see whats wrong?

Sorry for the late post! Been doing some many other stuffs in my pc. Any way, here is the script I use for saving a level externally; which is created through a sandbox in my game(which works very fine):
ds_list_clear(levelsave)
for (i=0;i<instance_number(all);i+=1)
{
inst = instance_find(all,i)
if (inst.id != self.id)
{
ds_list_add(levelsave,inst.object_index)
ds_list_add(levelsave,inst.x)
ds_list_add(levelsave,inst.y)
}
}
levelname = get_save_filename("BBXD Level (.bbxd)|*.bbxd",".bbxd")
if (!file_exists(levelname)){show_message("Fail to save file")}
if string_copy(levelname,string_length(levelname) - 4,5)!="BBXD Level (.bbxd)|*.bbxd" then
levelname=levelname+".bbxd"
str = ds_list_write(levelsave)
file = file_text_open_write(levelname)
file_text_write_string(file,str)
file_text_close(file)
Now create event:
global.add=4
global.lvl0=0
global.lvl1=0
global.lvl2=0
global.lvl3=0
global.lvl4=0
global.lvl5=0
global.lvl6=0
global.lvl7=0
global.lvl8=0
global.lvl9=0
change=0
I use this to play the level files:
change+=1

if change==1
{levelname = string(global.lvl0)}
if change==2
{levelname = string(global.lvl1)}
if change==3
{levelname = string(global.lvl2)}
if change==4
{levelname = string(global.lvl3)}
if change==5
{levelname = string(global.lvl4)}
if change==6
{levelname = string(global.lvl5)}
if change==7
{levelname = string(global.lvl6)}
if change==8
{levelname = string(global.lvl7)}
if change==9
{levelname = string(global.lvl8)}
if change==10
{levelname = string(global.lvl9)}
if change==11
{levelname = 0}
if (file_exists(levelname))
{
file = file_text_open_read(levelname)
str = file_text_read_string(file)
file_text_close(file)

ds_list_read(levelload,str)

for (i = 0; i < ds_list_size(levelload);i += 3)
{
index = ds_list_find_value(levelload,i)
xxx = ds_list_find_value(levelload,i+1)
yyy = ds_list_find_value(levelload,i+2)
instance_create(xxx,yyy,index)
}}
Now the problem is that it is not loading the string (file directory) when room starts. It plays the first level though but when moving on to the next, it doesn't load it. :confused:
  • 0

#4 lump

lump

    GMC Member

  • GMC Member
  • 64 posts
  • Version:GM8

Posted 22 April 2012 - 10:19 AM

how many instance are we looking at here because .INIs have a limit to the amount of characters in one of them, i think ist 1024 max so yeah. i've had that problem before. :unsure:

Edit:what i meant on my earlier post is: open up the .bbxd file and copy and paste the contents onto the sight so i may if it is infact the .bbxd. (although i think that is not the problem anymore :cool:

Edited by lump, 22 April 2012 - 10:22 AM.

  • 0

#5 Misu

Misu

    Awesometasticness!

  • GMC Member
  • 435 posts
  • Version:GM:Studio

Posted 22 April 2012 - 10:17 PM

I copy paste it here:

2D01000018000000000000000000000000001040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001040000000000000000000000000008094400000000000000000000000000000000000000000000000000000000000001440000000000000000000000000000040400000000000000000000000000000000000000000000000000000000000804840000000000000000000000000000040400000000000000000000000000000504000000000000000000000000000405740000000000000000000000000000050C0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000007C400000000000000000000000000000644000000000000000000000000000000040000000000000000000000000000084400000000000000000000000000000644000000000000000000000000000805740000000000000000000000000000086400000000000000000000000000000874000000000


But I also have a level editor where it actually loads levels that were already made and it works very well. But here is like it doesn't want to work now.
  • 0

#6 lump

lump

    GMC Member

  • GMC Member
  • 64 posts
  • Version:GM8

Posted 23 April 2012 - 11:07 PM

hmm, this may be more deep coded than i thought, let me look it over again. ;)
  • 0

#7 Misu

Misu

    Awesometasticness!

  • GMC Member
  • 435 posts
  • Version:GM:Studio

Posted 26 April 2012 - 08:51 PM

hmm...? :confused:
  • 0

#8 mn_beta

mn_beta

    GMC Member

  • GMC Member
  • 81 posts
  • Version:GM7

Posted 27 April 2012 - 10:01 PM

Write bytes, not strings.
  • 0

#9 Misu

Misu

    Awesometasticness!

  • GMC Member
  • 435 posts
  • Version:GM:Studio

Posted 29 April 2012 - 11:54 PM

Write bytes, not strings.

Um... that doesn't fix it at all but little by little, I'm seeking a solution and came across one that's working pretty fine. Well I guess from here and on, I'll handle this myself, guys. Thank you.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users