Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[VX] Dynamic Difficulty (V.1.1, Updated 17 March, 2008)

e

Sponsor

Pretty good idea there. The code could use a little cleaning up and Ruby-ism, but apart from that it looks good. :thumb:
I'm surprised no one had done something like that before. It's a pretty useful feature.
 
Actually, SephirothSpawn once did something similar for XP, and another user here requested that either it be updated for VX or something similar be coded.
I used Seph's old script for inspiration, but I believe I took it far enough in my own direction to avoid claims of theft.  It may not be the cleanest, but it should work.
 

e

Sponsor

Which is the important part. Clean code is mostly for other scripters who would use your script; admittedly, they represent a small percentage of the potential users. Like I said, it's a good script!
 

loam

Member

You asked for compatability ideas in your other thread. If you would still like some suggestions, I have a simple thought. Instead of commenting out what you don't want run, comment out what you do want run.

  • 1. In the enemy note, surround any code that belongs to your dynamic difficulty script with something like "=begin dynamic difficulty" and "=end dynamic difficulty". You will have to do this for every note with custom settings.
  • 2. Replace the eval(@note) line in your code with this:

    eval(@note.sub(/.*=begin dynamic difficulty/m,'').sub(/=end dynamic difficulty.*/m,''))

Since @note is a just string you can look at anything in it before you send it to eval(), even comments that eval() wouldn't be able to "see". The above code will removes the @note of everything up to and including "=begin dynamic difficulty", then removes "=end dynamic difficulty" and anything that follows, and then sends it to eval() to be run.

This ensures two things. First, your dynamic difficulty script will only evaluate what's in its own "code block" in the @note. It should ignore everything else, including code for other scripts and actual notes. Second, by making the "code block" out of an actual comment block (=begin and =end), if another script happens to be selfish and not share the note (i.e. it evaluates the whole thing), your code will stay in comments when the @note is evaluated and not be run.

So now other scripts won't interfere with yours, and yours won't interfere with others.

Of course the line can be changed to work for any other script by changing the regular expressions to =begin whatever and =end whatever.

Please ask any questions if you have them, or if it doesn't work.
 
Many thanks for taking on my request  :smile: I haven't had time to try it out yet but it looks like exactly what i needed.
 
loam, one question:  When another "greedy" script evaluates the whole note, as mine currently does, doesn't it still find the words "dynamic dificulty" after the "=end" and get really confused?

Edited the code to use the suggestion, but modified the closing tag to hedge my bets, since I don't actually understand how loam's suggestion works.
 

loam

Member

DrakoShade":10icymzx said:
loam, one question:  When another "greedy" script evaluates the whole note, as mine currently does, doesn't it still find the words "dynamic dificulty" after the "=end" and get really confused?

Edited the code to use the suggestion, but modified the closing tag to hedge my bets, since I don't actually understand how loam's suggestion works.

Unfortunately, "dynamic difficulty =end" won't work. Ruby block comments (=begin and =end) must occur at the start of the line or they will not be interpreted correctly. To see this for yourself, open up the rmvx script editor and take a look at a blank page. Or any page for that matter, we won't be here long. Type a bunch of random letters somewhere. "schmergleplex" is fine. Now type a "=begin" and "=end" anywhere above "schmergleplex". Your block comments will be coloured green by the script editor because they are comments, and schmergleplex will be black because it is a variable (undefined at that. You could make it = to "cat" if you want).

=begin
=end


schmergleplex = "cat"

Now, go up to "=end" and put a few spaces in front of it. Put "dynamic difficulty" in front if it if you want. See what happens.

=begin
dynamic difficulty =end

schmergleplex = "cat"

All of a sudden, "schmergleplex = cat" is green and commented out too. If you ran this script you would get an error because the "=begin" doesn't have a matching "=end". Now, because the new eval() you're using in your script removes the comment lines and won't evaluate them, you won't get an error from using your script. So if you tested it and it worked, that's why. But if another script evaluates the whole note for whatever reason, it will get an error (or at least, weird things will happen).


Actually, when I originally wrote the code I had the same fear you did, and was using this:

=begin #dynamic difficulty
=end #dynamic difficulty

But I tested it both ways and each seems to work fine. So if you are worried about it, or if problems do crop up, you could change it to that. I prefer the cleaner look as long as it works.

edit: And actually, I just realized a separate error with the code (I was up late when I did it ^^). Let me re-write the thing and get back to you.
 
Alright.  I'll temporarily revert the post, and when you have it worked out, I'll make sure that the updated script includes your name in a credits field.

I have a feeling that when you have that figured out, it may become a very commonly-used method.
 

loam

Member

This was supposed to be a pm but I didn't know you couldn't use spoilers in a pm. Instead of formatting the post all over it may as well just go here. It's an explanation of how to use some simple string methods to keep his script compatible with any others that use the notes in the map database, even if they don't use the same methods. But I'm serious: the method is one line long, yet the explanation is pages long. You probably don't need to read it. In fact, don't read it. Read at your peril...



Here's the deal. We have a script that evaluates enemy notes, so mapmakers can easily add custom variables/code right to that enemy. We want our script to still work if the mapmaker has added other code or comments to the same note. It would also be nice if the dynamic difficulty data didn't stop other scripts from working too. So that's the problem we're working with. Let's look at our tools.

eval() has some quirks but for what we're doing all we need to know is that it evalutes a string as if the string were a line of ruby. Let's start a new project and find an empty page in the script editor. We'll enter a few lines; an ordinary print(â€
 
By all testing, this works beautifully.  When I have the script appropriately commented and beautified, I'll update the first post to include the new version and appropriate credit!  Your explanation is insanely helpful, loam, and I'm thankful that you decided to help a newbie understand.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top