wuxiangjinxing wrote:Templayer wrote:Kaikhorus wrote:Both of the two trainers are in Free Haven. One is the Gong trader near the Mordreth quest giver, the other is in one of the homes near the boat/dock and the general trader.
I've made a new header under the Tutorials section on the Tracker for these, because people keep asking about the new teachers.
If some people would like to fill it more, it would make me happy.
Hey, could you give some suggestions on how to write the ascii of a string into memory?
For example, I want to write the string "Angel A" to the memory at 0x4f7dfc, currently what I'm doing is:
u2[0x4f7dfc] = string.byte('A')
u2[0x4f7dfd] = string.byte('n')
u2[0x4f7dfe] = string.byte('g')
... and so on
This works fine but the script would be very long. Is there a better way to do it? Thanks.
I am actually not the coder for the Merge. GrayFace and Rodril did most of the work.
I'm only proficient in Java. (and originally C, C++, C#, and Ruby but that was too many years ago)
I do not know if you read the manual for the Extension or not - disregard the original function extraction etc., since that has already been done in the package, and read it if you haven't already -
https://grayface.github.io/mm/ext/ref/
If you want to know how I would do it, if I can (this is one of many ways, presumably):
1. Create a function that puts a certain string into the memory (which is represented as an array in the Merge, with the keys being memory locations in hexadecimal and the values being the bytes inside said location). Two parameters - the string, and the memory starting point. ("Angel A" and 0x4f7dfc in your case would be the parameters) Possibly three parameters, if the function doesn't have access to u2, then the u2 as a third one. Probably called setStringToMemory or something like that. Better for it to be as widely useful as possible. In Java, we would put it into a class of *projectName*Utils, in this case MergeUtils.
2. Inside the function, in lua you would iterate over the individual chars inside the string (the string is basically an array of characters anyway, right?) - here's how:
https://stackoverflow.com/questions/829 ... lua-string - in Java, you would use a collection for this. "Note: In Lua string indices start at index value 1, not index value 0 (as they do in C)" - said the internet.
3. Inside the iteration, convert the iterated char into an ASCII code representation (i.e. that "string.byte(iteratedCharacter)" or whatever) and set it to memory location 0x4f7dfc with post incrementation of the said hexadecimal starting point variable. This basically means - in the first iteration (the first letter of the string), var pointInMemory will be 0x4f7dfc and in all subsequent iterations of the string characters, it is going to be pointInMemory (the previously set one) + 1 (in hexadecimal though).
4. Use the function in your code, which will take exactly one line of code to do per a String being added to the memory.
5. Find out that somebody already did something like that and you could have just used that and cry.
6. There might be a much easier solution somewhere. But programming-wise, this is a valid solution.
EDIT: I do not know what you are doing with this, maybe there should be a ceiling of the part of the memory you are editing so that you do not overflow your values into something else, and maybe the memory values from the end of your string up until some point should be empty if there was something there previously. In that case there would be another parameter to the function with the memory ending point, and it should throw an error if the string is a constant and is too long (going over), or be shortened and instead of an error thrown it should throw a warning into the log if the string is dynamic / non-constant.
I do not know if you didn't go through the Merge lua files already, but if you didn't, I would do that first, maybe there is already something like that somewhere.