The Dink Network

Reply to Re: Bah

If you don't have an account, just leave the password field blank.
Username:
Password:
Subject:
Antispam: Enter Dink Smallwood's last name (surname) below.
Formatting: :) :( ;( :P ;) :D >( : :s :O evil cat blood
Bold font Italic font hyperlink Code tags
Message:
 
 
January 23rd 2014, 09:37 AM
peasantm.gif
shevek
Peasant They/Them Netherlands
Never be afraid to ask, but don't demand an answer 
Ah yes I remember the problem. It wasn't related to getting editor_* values. The problem was that I used show_bmp ("...", 1); while player_map was on a different screen. That would mess with the background (which was to be expected) and hardness (which I didn't expect).

But this method gives us something we have been sorely missing: array variables. For an unused screen (or for any screen that doesn't use the editor_* values), we can use this as an array of globals, which can be indexed. It should make the chess thing a lot easier as well.

About hitting the limit, I've seen it too, even without using so many globals. The problem is that DinkC doesn't do garbage collection until it's done with executing scripts. I had a rather long nested loop to initialize a screen. This would hit the limit, because of all the locals that were kept around. Adding a few wait(1) statements solved the problem (and created others, which I solved by explicitly freezing Dink during the procedure).

Finally, if you don't need many bits per variable, you can store several of them in one actual global. It's not very comfortable to use, but it works. For example, to get and store a value in bits 4-6 of variable "storage", you can use:

int value = storage / 16 - (storage / 128 * 16);
say ("Value is &storage;, setting it to 2.", 1);
storage += 2 * 16 - value * 16;


(This is code which works in my preprocessor; I couldn't be bothered to make it real DinkC, if only because it would become unreadable. However, if you want to use it in a script without using my editor, I'm sure you'll be able to transform it yourself.)

This works because divisions are truncated to an integer, so a / 16 * 16 results in the value of a rounded down to the nearest multiple of 16. In fact, using this approach there's no reason to stick to powers of 2 (which makes it store things in bits); If you want to store a maximum of 3 numbers (0, 1 or 2) in a sub-variable you can just do a-a/3*3 to get the it (from the lowest bits).