![]() |
||||||||||||||
|
||||||||||||||
blade2k
» articles & tutorialsAdvanced Single Digit Splitting Algorithm
Knowledge Requirements: Change Variable, Variable No. (passing by reference), Common Events, Call Event, Change Switch, Fork Conditions, Event Conditions or Picture Commands Pros: Very reusable code, relatively simple to do if you understand Variable No Cons: Hard to understand if you don't know how to use Variable No, since I'm going for very flexible, it's a lot of code. -----Introduction----- This is a frequently asked for tutorial, as it is used in custom menu and battle systems quite a bit. There are other similar tutorials around, no doubt, but this one will use variable pointers, which few if any other similar tutorials will use. Now as the title says, this is an algorithm to split a 6 digit number (rm2k's maximum size) into 6 single digit numbers. This algorithm is best used if you use pictures or charsets of single-digit numbers. If you are using single-digit charsets, your numbers will looked quite spaced unless you have multiple versions (left, right, center). So it's best to use pictures if you don't want them appearing spaced out. This doesn't apply to double-digit charsets, as it is best to use a double-digit algorithm for them. Obviously that's not what this is. This particular version of digit splitting will be in a common called event. Note: This version is designed to be quite flexible and very forgiving, only the number to split has to be valid (between 1 and 5000), detects if the number is negative or positive, and only clears the value of the temp variable. Thus the actual code for this section is quite long. -----Quick Review Of Variable Pointers----- A variable pointer (Variable No) is like a piece of paper with directions. The value of the variable pointer tells you what variable number you will be using. So if the pointer has a value of 5, you will actually be using variable number 0005 and not the pointer itself. -----Description Of Single Digit Variables & Switches----- Variable0001 - pNumberToSplit - A pointer to the number you wish split up. Variable0002 - pOne - A pointer of what variable will hold the the one's digit. Variable0003 - pTen - A pointer of what variable will hold the the ten's digit. Variable0004 - pHundred - A pointer of what variable will hold the hundred's digit. Variable0005 - pThousand - A pointer of what variable will hold the thousand's digit. Variable0006 - pTenThousand - A pointer of what variable will hold the ten thousand's digit. Variable0007 - pHundredThousand - A pointer of what variable will hold the the hundred thousand's digit. Variable0008 - DummyVariable - Used in calculation of the sign. Switch0001 - SignPositive - A switch that indicates the sign of the number. Note: If a variable name has [ ] around it, that means I'm using the "Variable No" field. -----Algorithm For Common Called Event----- Fork pNumberToSplit less than 1 Message: "Variable pNumberToSplit must be between 1 and 5000." Else Fork pNumberToSplit greater than 5000 Message: "Variable pNumberToSplit must be between 1 and 5000." Else Change Variable DummyVariable, set to [pNumberToSplit] Change Switch SignPositive, set to on Fork DummyVariable less than 0 Change Switch SignPositive, set to off Change Variable [pNumberToSplit], multiply by -1 End If Change Variable [pOne], set to [pNumberToSplit] Change Variable [pTen], set to [pNumberToSplit] Change Variable [pHundred], set to [pNumberToSplit] Change Variable [pThousand], set to [pNumberToSplit] Change Variable [pTenThousand], set to [pNumberToSplit] Change Variable [pHundredThousand], set to [pNumberToSplit] Change Variable [pOne], Mod by 10 Change Variable [pTen], mod by 100 Change Variable DummyVariable, set to [pTen] Change Variable DummyVariable, mod by 10 Change Variable [pTen], subtract by DummyVariable Change Variable [pTen], divide by 10 Change Variable [pHundred], mod by 1000 Change Variable DummyVariable, set to [pHundred] Change Variable DummyVariable, mod by 100 Change Variable [pHundred], subtract by DummyVariable Change Variable [pHundred], divide by 100 Change Variable [pThousand], mod by 10000 Change Variable DummyVariable, set to [pThousand] Change Variable DummyVariable, mod by 1000 Change Variable [pThousand], subtract by DummyVariable Change Variable [pThousand], divide by 1000 Change Variable [pTenThousand], mod by 100000 Change Variable DummyVariable, set to [pTenThousand] Change Variable DummyVariable, mod by 10000 Change Variable [pTenThousand], subtract by DummyVariable Change Variable [pTenThousand], divide by 10000 Change Variable DummyVariable, set to [pHundredThousand] Change Variable DummyVariable, mod by 100000 Change Variable [pHundredThousand], subtract by DummyVariable Change Variable [pHundredThousand], divide by 100000 End Fork End Fork Change Variable DummyVariable, set to 0 Note: DummyVariable will always be 0 after this event is called, so don't count on it retaining values. -----How To Use This Algorithm----- There are 8 event commands you must give to use this common called event. - Change Variable pNumberToSplit, set to A (where A is the variable number that holds the value you want to split) (must be a value between 1 and 5000) - Change Variable pOne, set to B (where B is the variable number that you want the one's digit to be put) - Change Variable pTen, set to C (where C is the variable number that you want the ten's digit to be put) - Change Variable pHundred, set to D (where D is the variable number that you want the hundred's digit to be put) - Change Variable pThousand, set to E (where E is the variable number that you want the thousand's digit to be put) - Change Variable pTenThousand, set to F (where F is the variable number that you want the ten thousand's digit to be put) - Change Variable pHundredThousand, set to G (where G is the variable number that you want the hundred thousand's digit to be put) - Call Common Event -----Conclusion----- That's all folks. If you have a comment/question/suggestion, please feel free to e-mail me at voxvam@shaw.ca Good luck and have fun now :) |
|
|||||||||||||
|
©2002-2008 blade2k.net - parsed in 0.002 seconds - view active users
[15976 members][newest member: Onisan666]
Active Users (0)
|
||||||||||||||