No wonder nobody fuckin' scripts anymore
Could someone explain to me how to use Common Data?
I tried using it before but it had zero result.
I'm probably doing something wrong, but I can't find out what it is.
I was trying to make a spellcard captured/played counter for my game.
CommonData is, in short, a global variable that you can pass along between scripts, and even between play sessions. You declare a variable name and then give it a value, and that value can be accessed from any script you've made. For example, normally you would declare a variable within a script like
let variable = 4;And that variable can be accessed by anything within the braces (scope) it was declared in. To initialize common data with the same name and value, you would say
SetCommonData("variable", 4);And this value can be got from anywhere using
GetCommonData("variable"); For example,
number = GetCommonData("variable") + 6; would set the value of a variable called
number to 10. However, sometimes you may run into points where you want to get some common data but you haven't initialized it anywhere first. This is where you would use
GetCommonDataDefault("variable", 2); which would attempt to retrieve common data named "variable," but if it can't find any, it will return the value 2. All common data is deleted when you stop running the script, however, you can also save common data to be used when the player starts up the script at some other time, using the
SaveCommonData function, which writes all the current common data and it's values to a .dat file, which can be retrieved in a later play of the script using
LoadCommonData. There are many other useful common data functions, like saving values in groups using common data areas and stuff like that, feel free to experiment with all the functions you find
here.
So I have an enemy script, and I want to make a custom healthbar and timer and such appear. How would I do this without copy-pasting it in every script?
I've looked around #include_function, which apparently lets me paste a file's contents in my enemy script.
So I did it like this:
*c0d3z*
I'm missing that bit of info, does anyone know how to send that string over to the included script?
The
#include_function "script/path/name/here.txt"; command takes all the information from the text file
here.txt and pastes it in the script you declared
#include_function in, as if it was actually in that script. You'll even notice that when an error message pops up for something after the
#include_function command, it includes the lines from the included text file in the line count of the current file as if the included text was actually written in it. The text you put in this included file can be absolutely anything legal in danmakufu terms, that is, you can make a text file
here.txt and in it write only...
let variable = 2;...then say in some other file...
script_enemy_main{
let coordinate = 5;
#include_function "here.txt";
@Initialize{
//...etcAnd danmakufu will read it as:
script_enemy_main{
let coordinate = 5;
let variable = 2;
@Initialize{
//...etcSo as you can see, putting something like a seperate enemy script in the included function would probably yield an error. To go about doing your custom healthbar, script it up so that it works in one enemy script, then begin to transfer all the necessary code into a text file that may be included in other enemy scripts. Unfortunately, the easiest way to do this would be to make your healthbar thing a task which can be called from the enemy script and then run along side it using the enemy's yield command. If you really want to use the "MainLoop" method, you'll still probably have to seperate the healthbar from your MainLoop, but instead make it a
sub (or
function) instead of a
task. Something like:
"here.txt"sub Healthbar{
let obj = Obj_Create(OBJ_EFFECT);
//...etc
//insert your healthbar code here, exactly as if it was written in the @MainLoop of your enemy script.
}"hostscript.txt"script_enemy_main{
#include_function "here.txt";
@Initialize{
//...
}
@MainLoop{
Healthbar;
}
//etc
}