@Fujiwara No Mokou:You can't name a variable with quotes in it, and even if you could,
don't. ToString converts any other data type to a String. If you put quotes around anything, Danmakufu treats that (appropriately) as a String.
let v=5;
LoadGraphic(image[v]);
Would it ignore the array and load the picture named 'image[v]' because it doesn't recognize the array because there's no 'ToString' function? By the sound of it, I'm going to have to use ToString everytime I want to deal with variables and strings.
If the array "image" holds Strings in it, then you won't have to use ToString. For example:
let image = ["sound1.wav", "sound2.wav", "sound3.wav", "sound4.wav", "sound5.wav", "sound6.wav"];
let v = 5;
LoadGraphic(image[v]);
Will tell Danmakufu to load the graphic represented by the String in the 6th place of the array called image.
If the array held anything other than Strings, like numbers for example:
let image = [1, 2, 3, 4, 5, 6];
let v = 5;
LoadGraphic(image[v]);
This would error, because it's trying to load a number as a graphic (the 6th place in the array image is a number), which isn't possible. So you'd need to convert that number to a String so it would be read properly:
let image = [1, 2, 3, 4, 5, 6];
let v = 5;
LoadGraphic(ToString(image[v]));
Now this probably wouldn't do anything because you're trying to load a file called "6.000000" in your root directory, which probably doesn't exist. So in my example, I added
GetCurrentScriptDirectory to add a larger pathname to the file, and I also added ".png" to the end of the string to make sure it knows what file to load, specifically. ~ concatenates Strings.
By the way, would LoadGraphic(image~ToString(v)) work? Or, will I have to use "" to label what's the string, so LoadGraphic("image"~ToString(v));
No, neither would work. if image is a String:
let image = "effect";
Then you would have the following in the first example:
let v = 5;
let image = "effect";
LoadGraphic(image~ToString(v));
Loading a graphic called "effect5.000000". All numbers are stored as the
long data type in danmakufu, so converting any number to a string shows all the decimal places. In my
previous example, I added in code that shaves off all those needless decimal places.
For your second example, LoadGraphic("image"~ToString(v)); will load an image called "image5.000000", which is more wrong than the first example, heh. Again, Danmakufu treats everything inside quotes as a String, and it ignores any similarities the String may have with an existing variable.
Also, what if I want to use "" in my string? lets say the variable is I'm using is "v" . Could I just go on and plug in LoadGraphic("image"~ToString("v")); ?
Well, you can't start a variable name with a quote, so that's not possible. Disregarding the error I just mentioned regarding "image" being taken as a String instead of a variable, you'd still have to fix those quotes inside the strig by indicating to Danmakufu that those quotes do not end the String. There is a special character
\ which indicates to Danmakufu that some letter near it is meant to be treated as part of the String and not as it's special character identity. I'd explain how to use it, but Danmakufu fucks it up so hard that I honestly am not sure if it treats the next letter as a String, or the letter before it (it should be the one after it, but fuck some example I've seen).
For example:
Say you want to display
Awesome Sign "You Are Screwed"as a spellcard name. You'd need to have the following code in your CutIn:
CutIn(YOUMU, "Awesome Sign "\""You Are Screwed"\", "", 0, 0, 0, 0);
//the last five parameters are for the image, so ignore them
Now it looks like the
\ character is correctly indicating that the character after it is to be displayed properly, but by that logic the string ends at
"Awesome Sign "
Which is no good. Going the other way, if the \ character indicates the letter before it is to be left in the String, the String should end at
"Awesome Sign ""
Which is even more >: |
So I ask this to more experienced programmers than I, how does this escape character work!?What do I do if I want a number in a number of specified digits? Lets say...4
So a function that normally return 5 will return 0005, or a if it would return .05 to return 0.005
I want to avoid getting number that would normally return 15 return 00015. I would want that same function to return 0015 instead.
To display 00015, you would need to have it as a String. Numbers will automatically shave off all zeros before any non-zero number. So then you could just add zeros...:
let number = "000" ~ "15";
//number is now "00015"
Going the other way, you'd still need to convert the number to a String to prevent Danmakufu from displaying all six decimal places:
let number = 0.5;
let string = ToString(number);
//string is now equal to "0.500000"
loop(3){
string = erase(string, length(string)-1);
}
//string now equals "0.500"
Useful Miscellaneous Code Snippets, first post.
Drake's code adds commas and useless shit :V
EDITs: fixed my speedtypin' errors