Jump to content


Photo

Sprite_add, Saving And Loading It


  • Please log in to reply
20 replies to this topic

#1 REllU

REllU

    GMC Member

  • GMC Member
  • 190 posts

Posted 22 May 2010 - 01:32 PM

You may know my program, called "easy FPS"
I´m creating new beta of it, and i have this "little" problem...

- When you add textures to objects (like walls, and floors)
the program runs code like this:
itemtext="add textures"+string("|")+string(texturenames)
item=show_menu(itemtext,"")
if item=0{
newtex=get_open_filename("","")
obj_texture.owntex=sprite_add(newtex,...)}

And something like that. (i removed all of the code already, because it didnt work, so i dont remember all of it.)
I think you will understand the code.

So, the main problem isn´t adding the textures, no, it is saving and loading them again. And showing the texturenames in "show_menu" function
- I know, that this is somehow made with .ini:s, but i havent figured it out..

Please help!

BTW: i´m using GM8
  • 0

#2 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 22 May 2010 - 01:41 PM

... and i have this "little" problem...

A few things :

1) do not post untested code or, as you did, "something that was something alike something that could be doing something". The code is pretty-much bogus as it is (try it :))

2) Before posting research and try yourself first. If the code does not quite do what you expect of it post that code (a must in the Advanced subforum) together with a description of what its supposed to do, how it fails doing so, and what you think could be causing it.
Do NOT post (pretty-much) "I want something, you guys figure out what I need and tell me how to do it"

As a result this is moved to Novice.
  • 0

#3 REllU

REllU

    GMC Member

  • GMC Member
  • 190 posts

Posted 22 May 2010 - 01:53 PM

And this helped soo much... -.-'
Why the heck you quated me!?

And i think everyone understood what i´m going to..

I asked HELP, not rules.. I know them alraight...
ARGH!!
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Okay, something about the code:


obj_texture is object, that sets up every objects values.
mytex is the floors texture, that is set on obj_texture

And this peace of the code
"itemtext="add textures"+string("|")+string(texturenames)"
i putted it there so you can understand what i´m saying!

It works with just "itemtex="something""


And yeh, try it yourself..

I HAVE TRIED THIS F###ING THING SINCE LAST WEEK!!!!!

I have putted huge amount of hours to figuring out how this works!
I ALWAYS try to figure everything at myself, and now i´m trying to ask help!
--------------------------------------------------------------------
Thanks for your time

Edited by REllU, 22 May 2010 - 01:56 PM.

  • 0

#4 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 22 May 2010 - 03:05 PM

And this helped soo much... -.-'

I hope so. At least I took the time to explain to you why your question did not belong in Advanced and what you could do to make your question better.

Why the heck you quated me!?

Why I quoted you ? I do that in pretty-much all responses, it makes it easier for every one to see whom I am responding to. Whats the problem with it ? :P

And i think everyone understood what i´m going to..

All I understood was that you asked us to figure out what you really ment and spell out for you what you needed to do. I'm sorry for you, but thats not acceptable in Advanced, and to be frank, not liked in Novice either.

And this peace of the code
"itemtext="add textures"+string("|")+string(texturenames)"
i putted it there so you can understand what i´m saying!

Yes, I think I allmost understand what you meant there. Alas, I'm not at all sure as I have no idea why you used "texturenames" (did you mean multiple ? And if so, how ?), or why you think that a piece of text needs to be put inside a "string(...)" command.

I asked HELP, not rules.. I know them alraight...

No, you do not. At least not the rules to the Advanced subforum. Thats what I tried to make clear to you.

And yeh, try it yourself..

I HAVE TRIED THIS F###ING THING SINCE LAST WEEK!!!!!

If I may take your own word for it, what you posted is MAYBE the same as what you tried. Thats simply not good enough.

Try something that may be the same as the code you had ? You must be joking. I know more enjoyable ways to waste my time ... :)

I have putted huge amount of hours to figuring out how this works!
I ALWAYS try to figure everything at myself, and now i´m trying to ask help!

Than please post what you tried, what its supposed to do, and what problems you have with it. I want to see for myself that you really did something, instead of just believing you on your word. There are to many people around who seem to have adopted the "ask first, think later" strategy, expecting others to do work for them they could easily have done themselves.

Besides, maybe you made a simple mistake that can easily be rectified. Why do you expect us to waste our time on creating full working code and post it when a quick "look at that" pointer could be enough ?
  • 0

#5 REllU

REllU

    GMC Member

  • GMC Member
  • 190 posts

Posted 22 May 2010 - 05:08 PM

Phew.. I´m sorry for my later post.. I was just pissed of, cause i had headache, and i tried to work on the EFPS.. :)

But now, i changed my plans.
Now i´m trying to create an id system.

In the objects create, there is code like:

id2=obj_texture.id2
obj_texture.id2+=1

ini_open("texid.EFTEX")
obj_texture.mytex=ini_read("added textures",real(id2),"0")
ini_close()


and in the key pressed (when selecting the texture)
ini_open("texid.EFTEX")

path=get_open_filename("","")

ini_write_string("textures",real(obj_tex_shower.id2),string(path))


But now it wont write in the ini.. i really dont know why´s that :/
  • 0

#6 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 22 May 2010 - 05:16 PM

Phew.. I´m sorry for my later post.. I was just pissed of, cause i had headache, and i tried to work on the EFPS.. :)

Ah, thataway.

But now it wont write in the ini.. i really dont know why´s that :/

All three arguments in the "ini_write_string(...)" command must be strings, and you provided the second argument, the key, as a value.

P.s.
The third argument in there, the "path", is allready a string, it does not need to be enclosed in a "string(...)" command.

Hope that helps.
  • 0

#7 REllU

REllU

    GMC Member

  • GMC Member
  • 190 posts

Posted 22 May 2010 - 05:21 PM

Oh, i was stupid XD

Honestly, EFPS is first thing, where i used ini-files :)

Thanks!
  • 0

#8 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 22 May 2010 - 05:25 PM

Oh, i was stupid XD

Nah, Just a mistake.

Thanks!

You're welcome :)
  • 0

#9 REllU

REllU

    GMC Member

  • GMC Member
  • 190 posts

Posted 26 May 2010 - 03:59 PM

Ok, now i have problems with loading the map..

Now, with the new saving system, the program saves 3 files:

1: The actual save file
2: Txt, where is the paths of the textures
3: (the file, that you load) In this txt, there is path of the second, and first file.

So, there is this pease of code, when loads the map:

file = get_open_filename("Game Files|*.map","");
file_copy(file,filename_name(file))
mep=filename_name(file)
ini_open(mep)
aaa=ini_read_string("mapset","map","")
amount=ini_read_real("textures","amount","0")

{
  for (i=0; i<=amount; i+=1) texture[i] = i+1;
  sprite_add(texture,0,0,0,0,0)
}

game_load(aaa)

I really dont know, how the textures should been set..
I havent been used the for loop before, and i pretty much dont understand it..
:S
  • 0

#10 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 26 May 2010 - 06:01 PM

I really dont know, how the textures should been set..

I have a problem :

1) I do not see you loading the filename of the file which stores the textures

2) You are reading a real value from the INI-file which you did not describe anywhere

3) I do not see you attempt to read from the file which holds the paths to the textures


And a suggestion : you can store the paths/filenames of the textures in the .MAP (.INI) file too.
  • 0

#11 REllU

REllU

    GMC Member

  • GMC Member
  • 190 posts

Posted 27 May 2010 - 03:01 PM

the .map file is ini file.
There reads the paths

The loading works perfectly, but i just have to know, how i could set the textures?

And yeh, perhaps i could save everything in one txt..
We will see
  • 0

#12 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 27 May 2010 - 03:11 PM

The loading works perfectly, but i just have to know, how i could set the textures?

Use "background_add(...)" ?

I'm sorry, but as I do not know (can't decipher from what you posted) what your problem is (with the code) thats pretty-much all I can say.
  • 0

#13 REllU

REllU

    GMC Member

  • GMC Member
  • 190 posts

Posted 27 May 2010 - 03:24 PM

I already have the "sprite_add" code. And it adds the textures.

and in the txt file, where is all the textures, there reads (for example):
[textures]
0=textures/more textures/000.gif
amount=4
1=textures\001.gif
2=textures\002.gif
3=\textures\004.gif
4=textures\010.gif

The number means the ID of the object
  • 0

#14 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 27 May 2010 - 04:27 PM

I already have the "sprite_add" code. And it adds the textures.

and in the txt file, where is all the textures, there reads (for example): <snip>

Well, you've created a classical example of why its important to think about the information you're posting. Only with that ini-file example I understood what that code in your post at #9 is suposed to do. Referring to an .INI-file with the name "txt" (as in the extension used for text-files) was/is quite confusing and does not help either.

Alas, when I remarked to some things not being clear (my post at #10 :reading a real from an .INI file (I assumed was your .MAP file) ) but not getting any explanation to it in your "reply" did not help either.


But now I think I understood what you ment, so lets continue (from your post at #9) :
amount=ini_read_real("textures","amount","0")

{
  for (i=0; i<=amount; i+=1) texture[i] = i+1;
  sprite_add(texture,0,0,0,0,0)
}
1) Where are you reading the actual pathname strings (to the sprite-images) from the INI-file ?

2) What are you storing in that "texture[]" array, and why (for that matter, why are you using an array in the first place) ?

3) How do you think is that "sprite_add(texture,0,0,0,0,0)" line loading the sprites ? And why aren't you storing the result ?

The function returns the index of the new sprite that you can then use to draw it or to assign it to the variable sprite_index of an instance


Suggestion : do everything one step (one command!) at a time : first see if you can get "sprite_add(..) to work, only than see if you can use it in combination with something else.
  • 0

#15 REllU

REllU

    GMC Member

  • GMC Member
  • 190 posts

Posted 09 June 2010 - 09:12 AM

Okay, i figured it out, but now i REALLY dont understand, why the heck this wont work:

I have an object, named "obj_texture_loader"
And it is created when you want to load your map.


In its create event, there is this code:

file = get_open_filename("Game Files|*.map","");
file_copy(file,filename_name(file))
mep=filename_name(file)
ini_open(mep)
aaa=ini_read_string("mapset","map","")
texid=ini_read_string("mapset","eftex","")
ini_close()
file_copy(texid,"texid.EFTEX")
ini_open("texid.EFTEX")
amount=ini_read_string("textures","amount","0")
myid=0
alarm[0]=1

and in the alarm0 there is this code:

if myid<amount{
newtex=ini_read_string("textures",myid,"")
sprite_add(newtex,0,0,0,0,0)
alarm[0]=1
myid+=1
}

if myid=amount{
game_load(aaa)
}

:S
  • 0

#16 SenakuJin

SenakuJin

    GMC Member

  • New Member
  • 2765 posts

Posted 09 June 2010 - 09:48 AM

myid=0

if myid<amount{
newtex=ini_read_string("textures",myid,"")

-------------------------------------------------------------------------------------------------------------------------------------

I think its been mentioned before, but the function takes 3 strings as arguments. myid is a real. That may be the issue.

I suggest trying to debug based on returns. Almost every gml function has an error return if something goes wrong, and
as your storing the return in newtex, doing a simple: show_message(string(newtex)); on the next line will be valuable
to know. You can also store the return of sprite_add() and see if it returns a sprite resource index, or a -1 (load failed)

Edited by SenakuJin, 09 June 2010 - 09:54 AM.

  • 0

#17 REllU

REllU

    GMC Member

  • GMC Member
  • 190 posts

Posted 09 July 2010 - 02:46 PM

Okay BAAAD problem with the models..

So, when you create the model at the first time, it runs THIS sript:

laitettu=false
laittaa=false

alarm[1]=5
EFMO=get_open_filename("EFPS model files (*.EFMO)|*.EFMO;","")
if string_length(EFMO)>0{
file_copy(EFMO,filename_name(EFMO))
ini_open(filename_name(EFMO))
file=ini_read_string("EFMO","model","")
mytexe=ini_read_string("EFMO","texture","")
mymaske=ini_read_string("EFMO","mask","")
//myx=ini_read_real("EFMO","x-origin",2)
//myy=ini_read_real("EFMO","y-origin",2)



//file=get_open_filename("Model files (*.obj,*.gmmod)|*.obj;*.gmmod;","")
//mytexe=get_open_filename("Image files (*.bmp,*.gif,*.jpg)|*.bmp;*.gif;*.jpg","")
mytex=sprite_add(mytexe,0,0,0,x,y)
mymask=sprite_add(mymaske,0,0,0,0,0)
myx=sprite_get_height(mymask)/2
myy=sprite_get_width(mymask)/2
mask_index=mymask
myz=1
model = d3d_model_create();
d3d_model_load(model,file);
file_delete(filename_name(EFMO))
ini_close()

ini_open("texid.EFTEX")

obj_tex_shower.id2+=2
obj_tex_shower.modid+=1
myid=obj_tex_shower.id2
myidd=obj_tex_shower.modid
ini_write_string("model","amount",string(myidd))
ini_write_string("model",string(myidd)+"model",file)
ini_write_string("textures",string(myid-1),mytexe)
ini_write_string("textures","amount",string(myid))
ini_write_string("textures",string(myid),mymaske)
ini_write_string("model",string(myidd)+"x-origin",string(myx))
ini_write_string("model",string(myidd)+"y-origin",string(myy))
ini_write_string("model",string(myidd)+"EFMO",EFMO)
ini_close()

}



zekata=false



mydir=obj_tex_shower.modeldir
(laittaa, and laitettu is fin, and it means "put")


And so, when you create the model again, it runs in this script:

laitettu=false
laittaa=false
alarm[1]=5
ini_open("texid.EFTEX")


mydir=obj_tex_shower.modeldir
myid=obj_tex_shower.id2
myidd=obj_tex_shower.modid
file=ini_read_string("model",string(myidd)+"model","")
mytexe=ini_read_string("textures",string(myid-1),"")
mymaske=ini_read_string("textures",string(myid),"")

myzi=ini_read_real("EFMO",string(myidd)+"z2","0")

obj_tex_shower.modid+=1
obj_tex_shower.id2+=2
myid=obj_tex_shower.id2
myidd=obj_tex_shower.modid
ini_write_string("model","amount",string(myidd))
ini_write_string("textures","amount",string(myid))
ini_write_string("model",string(myidd)+"model",file)
ini_write_string("textures",string(myid-1),mytexe)
ini_write_string("textures",string(myid),mymaske)


//file=get_open_filename("Model files (*.obj,*.gmmod)|*.obj;*.gmmod;","")
//mytexe=get_open_filename("Image files (*.bmp,*.gif,*.jpg)|*.bmp;*.gif;*.jpg","")
mytex=sprite_add(mytexe,0,0,0,x,y)
mymask=sprite_add(mymaske,0,0,0,0,0)
myx=sprite_get_height(mymask)/2
myy=sprite_get_width(mymask)/2
mask_index=mymask
myz=1
ini_write_string("model",string(myidd)+"x-origin",string(myx))
ini_write_string("model",string(myidd)+"y-origin",string(myy))
model = d3d_model_create();

d3d_model_load(model,file);



And it works fine.
And when you load your map, it runs this code:

if myid<amount+1{
myid+=1
newtex=ini_read_string("textures",string(myid),"0")
sprite_add(newtex,0,0,0,0,0)
alarm[1]=1


}



else

myid+=1
newtex=ini_read_string("textures",string(myid),"0")
sprite_add(newtex,0,0,0,0,0)

and then it loads the models, which is working pefrectly.

So, whats the problem then?

Let me show you BEFORE/AFTER pics.

BEFORE- :
Posted Image

and AFTER the map is loaded:

Posted Image


DO NOT COPY THESE CODES! REllU HAS MADE THEM, AND YOU DONT COPY THEM IN YOUR GAME!!!!
  • 0

#18 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 09 July 2010 - 03:45 PM

Let me show you BEFORE/AFTER pics. <snip two images>

Nice. But you forgot to tell us what (you think) is wrong with them. Or do we have to guess. :mellow:

'Cause for all I know you could want those images to be red ... :whistle:

And if you do not want that (an educated guess) than you should, at the end of the code where you changed the color to red, change the color back to white again. :)

Hope that helps.
  • 0

#19 REllU

REllU

    GMC Member

  • GMC Member
  • 190 posts

Posted 10 July 2010 - 08:06 AM

Well, i have the colour changing code for the font, but no.
That is not the problem.

The textures, and mask´s are wrong, but i dont know why..

See the box in the right?

Texture of it, is it´s mask!
  • 0

#20 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 10 July 2010 - 09:31 AM

Well, i have the colour changing code for the font, but no.
That is not the problem.

This is exactly why I positivily hate having to guess. :(

The textures, and mask´s are wrong, but i dont know why..

See the box in the right?

Texture of it, is it´s mask!

Well, you did post code. But funnily enough you didn't post the code actually drawing those models(?).

I hope you did not just put the image into the3D draw-comand, but used a "background_get_texture(...)" on it to get to the texture ?

Also, what have you done to check if you are using the correct texture ? Have you looked at returned data from the "ini_read_string(...)", the "sprite_add(...)" as well as what you are putting into the 3D drawing command ? Does the "newtex" contain the correct filename, does the ....

Waitaminute !!!

In the "And when you load your map, it runs this code:" block you're not storing the result those "sprite_add(...)" commands. :huh: could that be it ?

But to continue, have you checked if the "mytex", "mymask" and possibly others contain values of zero-and-above (negative numbers mean failure), and if those values are still there and the same when you use them if the 3D draw-command(s) ?

If they are not you got a big problem (variables getting overwritten ?)

Hope that helps
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users