Code Monkey home page Code Monkey logo

Comments (5)

NathanLovato avatar NathanLovato commented on June 24, 2024

Note the project's generally outdated. It could use a complete rewrite, pretty much from scratch. Which I did, in part, by creating a new demo here: https://github.com/GDQuest/godot-2d-jrpg-combat

If you want to report and fix bugs that's fine, just note I'm personally focusing on newer, better-written projects.

from godot-open-rpg.

theraot avatar theraot commented on June 24, 2024

I picked an old repository because I worry I'll interfere with somebody else work.


I'll fix this. Except I went down a rabbit hole. The function randf is documented to be inclusive. I have confirmed experimentally that randf can output exactly 1 and exactly 0 (it took a while),

One would expect chance = 0 to mean never, and chance = 1 to be always. If I write:

if drop.chance < randf():
    continue;

Then when chance is 0 and randf is 0, that is false, and you would get the drop (it is not skipped). Which is wrong because chance of 0 is never.

If I write:

if drop.chance <= randf():
    continue;

Then when chance is 1 and randf is 1, that is true, and you would not get the drop (it is skipped). Which is wrong because chance of 1 is always.

So, I should write something like

if drop.chance < 1 and drop.chance <= randf():
    continue;

or

if drop.chance <= 0 or drop.chance < randf():
    continue;

And my brain wants to simplify that so badly… And it is so error prone! If I confuse < and <=, or and and or, or 1 and 0, it is wrong. I keep double guessing myself. I want a better way to write it, one where it is easier to notice if it is wrong.

With Microsoft (pseudo)random number generator (which I could use in C#), this is more intuitive, because it does not include the upper bound.

from godot-open-rpg.

NathanLovato avatar NathanLovato commented on June 24, 2024

Basically, you could get away with randf() <= drop.chance.

For the rest, if an item has a drop chance of 0, it shouldn't be in the list of items an enemy can drop, that's an error from the designer, and you could use an assert to prevent that.

If you want to be extra sure for the "should always drop" case, you can add a condition.

if is_equal_approx(drop.chance, 1.0) or randf() < drop.chance:
    # Add the items

That solves both problems.

from godot-open-rpg.

NathanLovato avatar NathanLovato commented on June 24, 2024

I picked an old repository because I worry I'll interfere with somebody else work.

When translating code to C#, you won't. If you have a doubt, open an issue or super WIP PR to say you'll be translating the code. As long as the repository isn't a work-in-progress, you're good to work on any.

from godot-open-rpg.

theraot avatar theraot commented on June 24, 2024

This is what I decided on: if drop.chance < 1 and randf() >= drop.chance:, I have the pull request ready (Edit: I mean, for this fix), I was testing.

from godot-open-rpg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.