Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bitcount() script command #3344

Open
wants to merge 3 commits into
base: stable
Choose a base branch
from
Open

Add bitcount() script command #3344

wants to merge 3 commits into from

Conversation

maqc1
Copy link
Contributor

@maqc1 maqc1 commented Mar 21, 2025

Pull Request Prelude

Changes Proposed

Add bitcount() script command to return the number of active bits in an integer. Also commonly called popcount. It is a basic operation that is usefull when dealing with bitmasks. Now, I know it can be done using functions, but isn't it nice to have a built-in command instead of relying on callfunc() for something that simple?

Script example:

NPC 1
if(bitcount(quest) < 2)
    mes "You need to talk to 2 different NPCs.";
else
    mes "Here is your reward!";

NPC 2
if(quest & 1)
    mes "You already talked to me.";
else
    quest |= 1;


NPC 3
if(quest & 2)
    mes "You already talked to me.";
else
    quest |= 2;

NPC 4
if(quest & 4)
    mes "You already talked to me.";
else
    quest |= 4;

@4144
Copy link
Contributor

4144 commented Mar 21, 2025

look like broken formatting in C code. Probably mix of tabs and spaces

@maqc1
Copy link
Contributor Author

maqc1 commented Mar 21, 2025

Oopsie, fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants