00:00
00:00
Newgrounds Background Image Theme

Dumbuhgly just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

(GMS2) Is there a way for my game to detect if it's running on newgrounds?

86 Views | 2 Replies
New Topic Respond to this Topic

Heya. Do any of you know how to make it so when I load up my game it first checks if it is running on Newgrounds or if it is running as an exe (downloadable version)? This is so if the game boots up on Newgrounds it turns off the discord presence code and enables so I can have advancements (using newgrounds api) for my game. Or if the game detects if it's running as an exe it enables discord presence and disables the newgrounds api stuff on that version.


Check out the Hell Alex Animated Trailer on Newgrounds!

Check out the Hell Alex Animated Trailer on Youtube!

BBS Signature

hello.


I don't know GMS2. I hope these are an adequate solution:


https://www.youtube.com/watch?v=bt0pZK890KQ (specially the section starting at 1:15)

https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Overview/Variables/Constants.htm (specially the section "Configuration Override")

https://manual.gamemaker.io/beta/en/Settings/Configurations.htm


since you already have separate builds for different platforms (HTML5 vs Windows), enable and disable code before building! don't this at runtime!


a superior solution better than macros is to have many files for each platform that implement functions with identical signature, but different behaviors, but during build select only one.


e.g. windows/discord.gml html5/discord.gml windows/newgrounds.gml html5/newgrounds.gml


however, I don't know if that is possible in GMS2 and I could not quickly find anything related on the Web, so until then, prefer macros


O prudente varão há de ser mudo,

Que é melhor neste mundo, mar de enganos,

Ser louco c’os demais, que só, sisudo


now, if you want to be perfectionist, there are criminal ways and correct ways to use macros.


this is the ultimate guide to portability and macro usage: http://doc.cat-v.org/henry_spencer/ifdef_considered_harmful.pdf


briefly, try to follow these three rules:


  • Never, ever, write conditional macros inside "ordinary" code.
  • Conversely, always keep it at "the top", confined inside a function or something equivalent.
  • Always test for features, never test for platforms.


I hope the following C code makes sense to demonstrate the above rules


this is okay:


#ifdef DISCORD
#define online_presence(STATUS) TellEveryoneAtDiscordYouArePlaying("My Epic Game", status[STATUS]);
#else
#define online_presence(STATUS) ((void)0) // Do nothing! Yes, nothing!
#endif

#ifdef NEWGROUNDS
#define ng_unlock(MEDAL) TellNewgroundsYouEarned(MEDAL)
#else
#define ng_unlock(MEDAL) ((void)0) // Do nothing!
#endif

void unlock(enum medal medal) {
  if (!is_unlocked[medal]) {
    StartAnimationForMedal(medal);
    is_unlocked[medal] = true;
    ng_unlock(medal);
  }
}

void damage_player(Player *player, int amount)
{
  if ((player->health -= amount) > 0)
    PlayHurtAnimation(player);
  else {
    unlock(MEDAL_FIRST_DEATH);
    PlayDeathAnimation(player);
    EndMatch();
    online_presence(STATUS_SELECTING_LEVEL);
  }
}

the following is a war crime:


void damage_player(Player *player, int amount)
{
  if ((player->health -= amount) > 0)
    PlayHurtAnimation(player);
  else {
#ifdef HTML5
    if (!is_unlocked[MEDAL_FIRST_DEATH]) {
      StartAnimationForMedal(MEDAL_FIRST_DEATH);
      is_unlocked[MEDAL_FIRST_DETH] = true;
      TellNewgroundsYouEarned(MEDAL_FIRST_DEATH);
    }
#endif
    PlayDeathAnimation(player);
    EndMatch();
#ifdef WINDOWS
    TellEveryoneAtDiscordYouArePlaying("My Epic Game", status[STATUS_SELECTING_LEVEL]);
#endif
  }
}

happy coding!


O prudente varão há de ser mudo,

Que é melhor neste mundo, mar de enganos,

Ser louco c’os demais, que só, sisudo