⌂ YolkfolkThe Dizzy Fansite
Community discussion

DizzyAGE General Coding Queries

Started by delta on 9 February 2008 • 258,915 views

721 posts
#62051
Hi Alex, i'm wondering if there is any way to alter things about setup.exe?

for example how do i change the name of the file it points at (set to dizzy.exe). Can i also change the scroll image it uses?

I ask because i'm wanting to do that for TLoD, and it occurred to me that although you can create 'non-dizzy' games with DizzyAGE, you can't actually have the .exe file for the game named as anything other than 'dizzy.exe'!
👍 0
#62053
Yes, you can change the setup.exe

Check it with a resource editor (ResHacker) and you'll find the images and the GS9 script responsible for everything. You'll figure out the available functions and how they work. Of course the basics of GS9 are the same, and of course the functions from the game engine not available.

Also, one can create a different setup, to set what is needed, as long as it works similar and writes in the dizzy.ini (which by the way I think it can't be renamed for non-dizzy games - the engine loads it by this name now).
👍 0
#62118
Alex, when i go into the setup.exe, the png files can only be saved as some obscure file type, not actually as a png. how do i load them into GIMP (or the like), and then reload them back into the setup.exe?
👍 0
#62119
Here is how I've just tested it it worked:

1. Open the setup.exe in ResourceHacker
2. Choose to save all resources
(you'll have the images as Data_1.bin, Data_2.bin, etc)
3. Rename the one you want to edit to have the extension .png
(for example Data_1.png)
4. Edit it in Photoshop and save it. (or in Gimp)
5. Rename back to Data_1.bin
6. Choose "Replace other resource" in ResourceHacker and browse for your file, Data_1.bin
Select:
ResourceType=FILES
ResourceName=BACKGROUND.PNG (in this case)
ResourceLanguage= (empty)
Hit Replace
7. Save file as setup.exe and test the result.

This is how I did it now, but probably you can skip some steps or so.

Also, you should be able to add other images in the same way and access them in the script. Just put them all under the FILES "type folder". Use png format to minimize the app size (TGAs will not be compressed like in the .pak).
👍 0
#62120
ok, thanks! i'll give it a go...
👍 0
#62124
ok, i've done that, but the image is a different size. i've changed #def WNDW to reflect this, and replaced the setup.gs file with the changed file, but it's still showing the old width. what have i missed?

akk i've also changed every instance of 'dizzy.exe' to 'tlod.exe', but it only runs it when the game is called dizzy.exe.

do i have to restart my comp for the changes to take effect?
👍 0
#62125
It should work by changing the WNDW and WNDH defines to the sizes of your image. I tried to downsize the window from Visual C by recompiling the application and it worked. It should be the same with the Resource editor. Just make sure the file is changed right.

The Image also represents the transparency region through the magenta color.

The executable is launched with:
gs_launch(`dizzy.exe`);
Search it in script and change it.

But you'll have a limitation with the dizzy.ini and dizzy.pak, as I said before.
Unless you use a hexadecimal editor and change this name in the game executable (it should be there) - just take care not to set a longer name or it will be really bad.
👍 0
#62126

yeahhhh i've got it now! for some reason when i uploaded the script and compiled it, it didn't work. {yolkfolk}:scratch:

so i've just been editing it in res-hacker and compiling it. works a treat!

Thanks, that's another job ticked off the list!

👍 0
#62127
alex, i'm now looking to change the key that the 'run' feature uses. at the moment it's 'shift' on the keyboard. how would i change this to 'control' (avoids clashing with windows stickykeys)

at the moment the code i use is:

shiftpressed = KeyboardStatus(0x2A) || KeyboardStatus(0x36);

what would be the codes for the control keys?

also, what code would i need to use to ensure this feature works with a joystick?

Thanks!
👍 0
#62128
DizzyAGE engine supports 256 keyboard keys, followed by 10 buttons for mouse and then the joystick with16 buttons and 4 direction keys (the joystick HUT).

The codes for control keys are: 0x1D (left) and 0x9D (right) (hezadecimal values)
The code for the first joystick button:
256+10 = 266 (decimal value)
The next joystick button is 267 and so one.

For the default player's control the engine uses the HUT direction keys for walk and jump (and the joystick axes of course) and the joystick's button 1 for jump, 2 for action and 3 for menu.

So you can try with button 4 (code 269) but I can't tell now where this button is on my gamepad, or on other joystick models. Anyway I think the joystick buttons can be rearranged from the driver, in case their placement is not convenient for a player.

When you have this feature ready, send me a build and I'll test it on my gamepad (a thrustmaster model).

Alex.

[EDIT]
If other codes are needed, they are listed in the engine's C/C++ sources (Engine/Input) or in the editor.pak script files (keyboard).
Or I can upload the file here.
👍 0
#62129
thanks alex, what code would i actually use to incorporate code 269 into the coding?

would it be 0x10D?
👍 0
#62130
yes, and you can enter the integer numbers in any format, decimal or hexadecimal. For the engine it's the same.

For example colors are easy to enter in hexadecimal, like 0xff0000 for red (transparent in this case), because the color channels are more visible. But you can enter it in decimal too.
👍 0
#62131
thanks alex, i'll send you a message with a link to download the final beta version when it's ready (probably 4-8 days time). just really putting the final graphical touches to it, as well as the odd little coding tweak.
👍 0
#62150
IMPORTANT:

Forget about checking joystick buttons with the KeyboardStatus functions - it was accepting only keyboard values.

Get DizzyAGE v2.2.1 and use JoystickStatus(key) key=[0..19] and JoystickAxe(axe) axe=[0..7].

And it's best to use the button mapping options from the dizzy.ini (joystick_b3 in your case - for running). Some users may want to remap their buttons and the engine does use these custom values.

Just get the joystick_b3 value when you start your game and use it with JoystickStatus. It should be 3 by default, but as I said, someone may want to change it.
👍 0
#62309
right, i'm trying to get DizzyAGE to choose truly random numbers, rather than psuedo-random numbers as it does at the moment.

the issue is that 9 times out of 10, BTD will start with the same screen, rather than a random one. of course it does 'randomly' choose a screen, but it just isn't very random, due to the way computers choose random numbers.

i'm currently trying to think of a way to use the current time (in seconds) or the current frame to choose it, as it would be a lot less predictable that way. however it has to work for a range of numbers. so i can't just say 'pick whatever the second digit of the time is', as if you only want a range of 6 numbers, it wouldn't be much good if the game picked an 8...

hmmm....
👍 0
#62310

ok, so here is how to create a random number generator:

Define G_CURRFRAME in def.gs

then put the following code in the HandlerGameUpdate() function in handlers.gs:

GameSet(G_CURRFRAME,GameGet(G_CURRFRAME)+1);
if (GameGet(G_CURRFRAME)==60) { GameSet(G_CURRFRAME,0); }


the number 60 is an arbitrary number, you cannot call a random number higher than this. if you need to call a higher number, change 60 to a higher number

and put the following code in utils.gs:

/////////////////////////////////////////////////////////
//randomiser based on a game frame counter
/////////////////////////////////////////////////////////
func time_rand(num)
{
sec = GameGet(G_CURRFRAME);

// if number range required is lower than the 'frame' number,
// reduce that number in increments until it is lower
if (num-1< sec) { for(i=sec;i>num-1;i-=num)
rand = i-num;
}
else // else set the random number as whatever the 'frame' number is
{
rand=sec;
}
GameSet(G_CURRFRAME,60-sec);
return rand;
}

when called, this basically finds the current game 'frame' number. if it is lower than the random number range, it sets the random number as that, otherwise it reduces it in increments until it is lower, then sets the random number as the resulting number.

the beauty of this is that is really is truly random, as the frame counter changes so quickly that it's impossible to 'fix' it to the same number again and again. it depends on when various things in the game happen, rather than an in-game number generator. {yolkfolk}:delight:

unfortunately if you request another random number straight after, the frame count will not have moved on, so if the start number is the same, the resulting number will be the same too. Still working on how i can fix that...

EDIT:: thought of a way to do it. i added GameSet(G_CURRFRAME,60-sec); near the end, which has the effect of 'reversing' the number, ready for if there is a command calling it straight after. again, if you change the number '60' in the handler code, you will need to change it here too. :smile:

👍 0
#62321
DizzyAGE GS9 uses the standard random generator, available in C/C++ (probably the same as in any other languages). This generator should be enough for most of the games.

So in GS9, to get a random number, use gs_rand(range) for integers and gs_frand(range) for floats. Now these, as any other algorithms that a computer could use, are pseudo-random numbers, but due to the implementation they should look pretty random.

The random algorithms are based on a given seed number to start with, and they generate the next number based on the value of the last one (or the seed, for the first time). However the generation code is based on known mathematic formulas, to produce very different values.

In GS9 use the gs_srand(seed) to give the random seed. Now, if you set this seed to a fixed number, you will get the same sequence of random numbers each time you launch the game. That's why games usually initialize the random generator with a seed based on the current tick time, when the game application starts (you can get that with gs_time() in GS9).

This is standard for games, and it usually produces good results.

Now 9 out of 10 with the same result is not "very random". It might be something wrong.
Have a look at the example of gs_srand in the GS9 book, and do a small test at the begining of the game:

gs_srand(gs_time()); // variable seed
println(gs_rand(100)); // will print different numbers each time

By default, I think the random seed is initialized by the DizzyAGE engine in this way, with a time based value. I hope gs_time() reports the computer time in milliseconds as intended, not an internal counter starting from 0 :smile:

And if you are to use another random generation algorithm, have a look on the internet about how to do it. It isn't that complicated and it should work much better than your's. And of course it can be done in GS9 too :smile:

Alex
👍 0
#62322
[quote data-userid="17" data-postid="62321"]

gs_srand(gs_time()); // variable seed
println(gs_rand(100)); // will print different numbers each time

[/quote]

i did that in start.gs, but changing the 100 to 6, as that is the minimum 'random' range i need, and got the number 2 six times in a row, straight from the start.

having said that, now i'm getting random numbers. :smile:
👍 0
#62323
Well, with random numbers you could get the same values in a row - they all have the same probabilistic eights - though this is rarely happening in the Loto games :smile:

Anyway, if you want to avoid such situations (like 4-6 times the same value in a row) you could retry the generation a few times, until you like the results (remember last values).
👍 0
#62716
right, another point at which i'm stuck.

basically i'm trying to duplicate the Inventory coding.

I'm using a table at the moment, as trying to duplicate G_INVENTORY didn't seem to work.

basically the problem is that if i 'add' something to the inventory, then try to find it using the equivalent of InventoryFind(idx); it returns 0 value. every time. for every inventory slot.

hang on a mo...

never mind.... i was setting tham all to 0 value at the start, and when it was trying to place them there, it was only looking for slots with a value of -1, so wasn't adding them... It's now working perfectly :smile:
👍 0