Jump to content


Photo

D3d_model_duplicate


  • Please log in to reply
4 replies to this topic

#1 Schreib

Schreib

    Valen Shadowbreath

  • GMC Member
  • 1455 posts

Posted 20 August 2007 - 12:55 PM

Well, kind of straight-forward. This script duplicates a model which you have created in Game Maker and returns it's new index.

PRE
/*
** Usage:
** newmodel = d3d_model_duplicate(oldmodel);
**
** Arguments:
** oldmodel the model you wish to duplicate
**
** Returns:
** the index of the duplicated model
**
** GMLscripts.com
*/
{
var oldmodel, nindex;
oldmodel = argument0;
d3d_model_save(oldmodel,temp_directory+"\ju830ASD83889.mod");
nindex = d3d_model_create();
d3d_model_load(nindex,temp_directory+"\ju830ASD83889.mod");
file_delete(temp_directory+"\ju830ASD83889.mod");
return nindex;
}


Note that the temporary filename was assigned by frequently banging my head against the keyboard... :blink:

Edited by Schreib, 20 August 2007 - 12:56 PM.

  • 0

#2 Fede-lasse

Fede-lasse

    AI Programmer

  • GMC Member
  • 2009 posts
  • Version:Unknown

Posted 29 February 2008 - 09:31 PM

Why not:

/*
**  Usage:
**      newmodel = d3d_model_duplicate(oldmodel);
**
**  Arguments:
**      oldmodel      the model you wish to duplicate
**
**  Returns:
**      the index of the duplicated model
**
**  GMLscripts.com
*/
{
    var oldmodel, nindex, modelid, modelext;
    oldmodel = argument0;
    modelid = ""
    modelext = choose(".d3d",".mod")
    repeat(floor(random(10))+1) { modelid+=choose(string_char_at("QWERTYUIOPASDFGHJKLZXCVBNM",floor(random(string_length("QWERTYUIOPASDFGHJKLZXCVBNM")))),string(floor(random(11)))) }
    if file_exists(temp_directory+"\"+modelid+modelext) { do { modelid+=choose(string_char_at("QWERTYUIOPASDFGHJKLZXCVBNM",floor(random(string_length("QWERTYUIOPASDFGHJKLZXCVBNM")))),string(floor(random(11)))) } until !file_exists(temp_directory+"\"+modelid+modelext) }
    d3d_model_save(oldmodel,temp_directory+"\"+modelid+modelext);
    nindex = d3d_model_create();
    d3d_model_load(nindex,temp_directory+"\"+modelid+modelext);
    file_delete(temp_directory+"\"+modelid+modelext);
    return nindex;
}

It doesn't overwrite previous models if the function is called twice at the same time by generating a completely random model name.
Hope it helps :(

Btw, I haven't tested this yet, but it should work.

- Fede-lasse
  • 0

#3 Schreib

Schreib

    Valen Shadowbreath

  • GMC Member
  • 1455 posts

Posted 02 March 2008 - 07:57 PM

I'm quite sure most users don't have something called ju830ASD83889.dat or ju830ASD83889.mod in their game directory :GM072: . The file is deleted before the script proceedes, so there is no risk that if you are copying two models at a time the other one will be overwritten. I weigh the positive parts with my script (quite fast) over the negative parts (no unique name taken into consideration).

I appretiate your will to improve though.

Edited by Schreib, 02 March 2008 - 08:01 PM.

  • 0

#4 Fede-lasse

Fede-lasse

    AI Programmer

  • GMC Member
  • 2009 posts
  • Version:Unknown

Posted 05 March 2008 - 02:30 PM

Lol, now when I think, "my" script is completely useless.
I guess that was just a waste of my time :P

no unique name taken into consideration

Stop saying such a thing; everyone knows that you're talking about me anyway :unsure:

- Fede-lasse
  • 0

#5 japjap

japjap

    GM-LINUX GM-PS4 user

  • New Member
  • 124 posts
  • Version:GM8

Posted 27 November 2011 - 11:55 AM

Can you make a sample for beginners to this?
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users