The Dink Network

Checking globals from previous DMods?

June 11th 2013, 06:51 PM
knights.gif
dinkkiller
Peasant He/Him United States
The world could always use more heroes 
Is it possible to have a script check for a global in another D-Mod?

For example: A previous D-Mod you made had certain events happen, and in your new D-Mod, you want to check whether the player did or did not do something in that D-Mod based on the value of a global, to determine whether a chain of new events will be triggered in the new D-Mod.

I'm not really sure how to explain this better. Basically I'm trying to pull a Mass Effect type thing. Is it possible to do this?
June 11th 2013, 07:39 PM
wizardg.gif
Er, maybe?

I'm not exactly sure if this would work or not, but The Catacombs by Paul transfers your stats from the original game by moving the save file over. So it would keep the globals of &strength, &defense, &magic, etc. So as long as you have the same globals in the first game as you do in the second then sure.

The player will likely have to use the transfer dmod if they want that Mass Effect deal going on.

Though you should still make it playable without using said transfer system.
June 11th 2013, 07:47 PM
knights.gif
dinkkiller
Peasant He/Him United States
The world could always use more heroes 
Well at the moment I just have a little choice menu thing asking the player if they did the certain thing I'm looking for in my first D-Mod (also similar to certain Mass Effect things if you hadn't played previous games.) It's only one little thing, because I just added it to v1.03 (which hasn't been approved yet) and it's pretty minor. I'll probably just get rid of that choice menu and just work that sub-plot into my new D-Mod anyway.

However, this will end up a 3 part D-Mod series, so if it is possible to transfer globals/saves over, with what I'm planning on doing with my current D-Mod, transferring saves/globals into part 3 will be almost certainly necessary.
June 11th 2013, 08:02 PM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
Only through saved games. If you make_global_int() the same global in both D-Mods, then you can copy a savegame from the first D-Mod to the second, and when it's loaded, it'll have the same value as it had in the first game.

There is a pitfall with map data, though. Smashed barrels and such are also stored in the savegame data, and you don't want random sprites to be replaced by flat barrels or boxes, or have them not show up at all (which can happen if your quest-giving NPC just happens to have the same editor number on the same map number as a rock you exploded in the previous game).
Make sure to call clear_editor_info() whenever you load a saved game from another D-Mod. Also make sure to not call clear_editor_info() whenever you load a saved game from the same D-Mod, or else the rock you exploded in this game will show up again (and worse: that chest with the megapotion? Will have another megapotion).

Also, as Leprochaun warns, make sure the D-Mod is playable without having played the previous game. Also consider what happens if the player didn't level as much as you expect, or leveled way more than you expected. You don't want combat to be impossible, or too easy.

Hopefully, the following snippets of code will work. Beware: they are untested. Mess with savegames at your own risk

// main.c in the "new" D-Mod.
// Make sure you initialize &player_map as 0.
// You set it to the starting screen in "start-1.c", or whatever script you have on the start button.
make_global_int("&player_map",0);
// Add this line to the list of globals.
// Use a variable name that does not occur in any of the scripts of the "old" D-Mod.
make_global_int("&version",0);

// Add the following bit to the end:
if (&player_map > 0)
{
  // We're likely loading a game.
  if (&version == 0)
  {
    // This means we're loading an "old" D-Mod game.
    clear_editor_info();
    // Do all other things here.
    // Resetting story-related variables if needed, removing items and spells, you name it.
    // Also, set this. This is important.
    &version = 1;
  }
}


// In start-1.c, or whatever the script of the start button is.
&player_map = 400;
// The following says that we're in the "new" D-Mod.
// Loading a game will see this value, and skip the transfer code.
&version = 1;


This relies on the fact that main.c gets re-run when you load a savegame. make_global_int() does nothing if the global already exists, and adds it with default value if it doesn't. Since &version does not exist in the previous D-Mod, it'll be given default value 0, which triggers the transfer code. &version does exist in this D-Mod, and is set to 1 at the start of the game, and also after importing the savegame.
June 11th 2013, 09:07 PM
knights.gif
dinkkiller
Peasant He/Him United States
The world could always use more heroes 
Well thanks. I can mess with this stuff if I ever make part 3 of my trilogy. I don't think I'll try using it for The Quest for Death as I'd only need it for one side-story related thing from v1.03 of Dink and the Bonca (once a staff member decides to approve it.) I wouldn't use it to store stats from the previous game because I have some clever story elements that reset Dink's stats to noob level at the beginning of each game.

Or I could just pull an anti-Mass Effect where the choices you make don't matter between games. lol
June 14th 2013, 05:57 PM
peasantm.gif
shevek
Peasant They/Them Netherlands
Never be afraid to ask, but don't demand an answer 
If you want to use the savegame approach, you can also check Friends Beyond 3; it is a 2-part dmod, where you have to change maps when changing; it keeps the savegames and uses that to find out at the beginning of part 2 what your stats were at the end of part 1.

There are quite some bugs in it, though (most not too annoying IMO), so I'm not sure how well this part was implemented. I haven't noticed anything that seemed to be caused by it, but I don't know if I would notice this as the cause.
June 14th 2013, 10:30 PM
knights.gif
dinkkiller
Peasant He/Him United States
The world could always use more heroes 
Well, the ideas for part 3 of my trilogy are still in the earliest stages. Whether I'll need to attempt a save game transfer from part 2 (I'm working on now) to part 3 will be determined once I finish The Quest for Death. But thanks, At least I know I have something to go off of to implement this idea.
June 15th 2013, 12:22 PM
custom_iplaydink.gif
iplaydink
Peasant He/Him Sweden
Hmm.. 
Couldn't you write a program (outside dink) that read the old save and copied the values you are interested in to the new startup script?

You'd have to instruct the player to run that program first before starting the dmod... you could even check it in the startup by setting the variable to something (like 99 for example) befor it is replaced, and if it still is that on startup you could force it to show instructions and then shut down...

Am I making sense?
June 15th 2013, 04:43 PM
knights.gif
dinkkiller
Peasant He/Him United States
The world could always use more heroes 
I wouldn't want to force the player to do a bunch of stuff that's required to do before being able to play the D-Mod. This concept was just an idea in my head based on my love of Mass Effect and what I'm trying to incorporate into my D-Mod. As for writing my own program, I don't think I'm even capable of doing that.