Jump to content


Photo

Mapping All Scripts


  • Please log in to reply
18 replies to this topic

#1 ~Dannyboy~

~Dannyboy~

    ~hoqhuue(|~

  • GMC Member
  • 2144 posts
  • Version:GM8

Posted 02 June 2009 - 08:01 AM

Hey everyone,

I'm looking for a way to create a map of all script resources, this is for use in my proposed system for the GMCG. It would be very useful to be able to keep track of the scripts without having to manually add them to a list.

As I'm sure many of you know there are a number of resource mapping scripts on gmlscripts.com; unfortunately there is no script for mapping scripts, I'm assuming this is because the author hit the same hurdle...

The problem is that no scripts can be created in game and therefore the maximum number of scripts cannot be determined. The only logical workaround I can think of is to have the caller guess the maximum number of ids (of course if you enter a huge number you're fairly sure you'll get all the scripts).

So basically my question is, is this the best way of doing this?
PRE
// scr_map_scripts(map, max)
{
    // We assume there are no more than 'max' script ids
    // Is this really the best solution?
    var i;
    for (i = 0; i < argument1; i += 1)
    {
        if (script_exists(i))
        {
            ds_map_add(argument0, script_get_name(i), i);
        }
    }
}


Your expert opinion would be appreciated, thanks,
~Dannyboy~
  • 0

#2 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1730 posts
  • Version:Unknown

Posted 02 June 2009 - 08:08 AM

Yeah, I've run into similar situations with those mapping scripts. I think you'll be hard pressed to find a better solution. The nice thing though is that you should really only have to call that script once at the beginning of the game. So if it takes a few seconds to run it shouldn't be too big of a deal. Just make sure everyone understands that things may start getting buggy if they exceed the max without updating it. Also make sure to give yourself plenty of head room. My personal project's script IDs are already up over 2500 (there's not 2500 scripts, but the IDs have worked their way up to that), so I could foresee a group project like that getting pretty high.
  • 0

#3 ~Dannyboy~

~Dannyboy~

    ~hoqhuue(|~

  • GMC Member
  • 2144 posts
  • Version:GM8

Posted 02 June 2009 - 08:34 AM

2500 script ids, that is a lot! Thanks for you input, looks like I'm stuck with guessing the maximum number. I thought that'd be the case, but still it doesn't hurt to ask. :)

Edited by ~Dannyboy~, 02 June 2009 - 08:36 AM.

  • 0

#4 Schyler

Schyler

    Noskcirderf Derf

  • GMC Member
  • 2445 posts
  • Version:GM8.1

Posted 02 June 2009 - 11:37 AM

Loop until script_get_name() returns blank? Or -1?

EDIT:
while(1)
{
	 blabla; { break; }
}
^ Just in case you hadn't thought of this way.

Edited by Schyler, 02 June 2009 - 11:38 AM.

  • 0

#5 DarkSentinel

DarkSentinel

    GMC Member

  • New Member
  • 1965 posts

Posted 02 June 2009 - 12:11 PM

Yes, but if a script was deleted there would be a gap in the script indices and your loop would break prematurely.
  • 0

#6 slayer_jojo

slayer_jojo

    GMC Member

  • New Member
  • 181 posts

Posted 23 July 2009 - 03:29 AM

What about storing the scripts in external files, and then using execute_file(fname,arg0,arg1,...) .  Or is this function slow?

You could scan a directory and simply map all the scripts in it if so
  • 0

#7 cmd

cmd

    GMC Member

  • New Member
  • 191 posts

Posted 23 July 2009 - 08:52 AM

You could loop until it gets so many fails in a row. Maybe 20? Or look what the biggest gap is in your script ids and double it.
  • 0

#8 HaRRiKiRi

HaRRiKiRi

    GMC Member

  • GMC Member
  • 1364 posts

Posted 23 July 2009 - 12:06 PM

I don't think script_exists function is that slow, thus it would not take too long to loop trough 2500 indexes and check if ID exists. So this seems the only fast and possible way to do this.
  • 0

#9 slayer_jojo

slayer_jojo

    GMC Member

  • New Member
  • 181 posts

Posted 24 July 2009 - 08:45 PM

@cmd

I have never heard of anything that sounded less elegant
  • 0

#10 THE KAPPTIN

THE KAPPTIN

    El Capitano

  • New Member
  • 2374 posts

Posted 24 July 2009 - 09:29 PM

@cmd

I have never heard of anything that sounded less elegant

Would you rather have a beautifully-carved table of balsa wood, or an ugly one that works?

It seems like a reasonable solution, if nothing better crops up. It's very similar to the "guess the max number of scripts" method, but requires less frequent updating.
  • 0

#11 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1730 posts
  • Version:Unknown

Posted 24 July 2009 - 09:49 PM

I have never heard of anything that sounded less elegant

[...]
It seems like a reasonable solution, if nothing better crops up. It's very similar to the "guess the max number of scripts" method, but requires less frequent updating.

I agree. Although to be useful the gap would probably have to be put much higher than 20. More in the 250-2000 range I think, depending on the project. But still, it will require less updating than a set number and be about as elegant of a hack as you can come up with in this situation I think.
  • 0

#12 slayer_jojo

slayer_jojo

    GMC Member

  • New Member
  • 181 posts

Posted 24 July 2009 - 10:27 PM

If it was a 500 or so gap that would be better (this is only done once in the game).  The way he worded it though made it sound extra inelegant.  And I still don't like it (but, what'ev).

Also, please don't use "analogies".  Almost all of them fall under this fallacy:

http://www.fallacyfi...g/wanalogy.html
  • 0

#13 ~Dannyboy~

~Dannyboy~

    ~hoqhuue(|~

  • GMC Member
  • 2144 posts
  • Version:GM8

Posted 25 July 2009 - 01:33 AM

So you suggest something like this? I guess it's slightly better.
PRE
// scr_map_scripts(map, max)
{
var i, j;
i = 0;
// We assume there aren't max ids "missing" in a row
for (j = 0; j < argument1; j += 1)
{
if (script_exists(i))
{
ds_map_add(argument0, script_get_name(i), i);
j = 0;
}
i += 1;
}
}

Side note, if only the comma operator was supported in GML, then the following would work. Oh well.
PRE
// scr_map_scripts(map, max)
{
var i, j;
// We assume there are no more than max ids "missing" in a row
for (i = 0, j = 0; j < argument1; i += 1, j += 1)
{
if (script_exists(i))
{
ds_map_add(argument0, script_get_name(i), i);
j = 0;
}
}
}

  • 0

#14 Pinpickle

Pinpickle

    Abscure Programmer

  • GMC Member
  • 1353 posts

Posted 25 July 2009 - 06:20 AM

Side note, if only the comma operator was supported in GML, then the following would work. Oh well.


You mean like this?
// scr_map_scripts(map, max)
{
	var i, j;
	// We assume there are no more than max ids "missing" in a row
	for ({i = 0 j = 0}; j < argument1;{i += 1 j += 1})
	{
		if (script_exists(i))
		{
			ds_map_add(argument0, script_get_name(i), i);
			j = 0;
		}
	}
}

  • 0

#15 ~Dannyboy~

~Dannyboy~

    ~hoqhuue(|~

  • GMC Member
  • 2144 posts
  • Version:GM8

Posted 26 July 2009 - 05:43 AM

You mean like this?

Can't believe I didn't know that, learn something new everyday, thanks :)
  • 0

#16 xot

xot

    media multimixer

  • Global Moderators
  • 4647 posts
  • Version:GM:Studio

Posted 27 July 2009 - 05:19 AM

You mean like this?

Can't believe I didn't know that, learn something new everyday, thanks :ph34r:


Indeed, that's a new one to me as well. If you wanted to get silly, ds_map_add returns zero. You could assign that to j in the same statement.
  • 0

#17 LumiéreDuSoleil

LumiéreDuSoleil

    Long Live the Sun

  • New Member
  • 55 posts

Posted 28 July 2009 - 01:32 AM

o.0

Pack the entire script into one for() and it still works. Nice find, Pinpickle.

// scr_map_scripts(map, max)
// We assume there are no more than max ids "missing" in a row
for ({
		var i, j;
		i = 0;
		j = 0;
	}; 
		j < argument1;
	{
		if (script_exists(i)) {
			j = ds_map_add(argument0, script_get_name(i), i);
			}
		i += 1;
		j += 1;
	}){}

  • 0

#18 dark_master4

dark_master4

    GMC Member

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

Posted 28 July 2009 - 06:17 PM

OK. That last one was just too much LumiéreDuSoleil lol. But it is a really NICE find!!
  • 0

#19 MitchGraham

MitchGraham

    GMC Member

  • Banned Users
  • 524 posts

Posted 28 July 2009 - 07:14 PM

Wasn't I the one who taught you that, Pinpickle? o_O




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users