CustomInventory "system" question

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
User avatar
DoomRater
Posts: 8270
Joined: Wed Jul 28, 2004 8:21 am
Preferred Pronouns: He/Him
Location: WATR HQ
Contact:

Re: CustomInventory "system" question

Post by DoomRater »

AND does a binary AND compare against a number. Since they are all added to each other, the only way to keep them from interfering with each other is to make sure the numbers are all powers of a certain number (2 in this case), and the binary AND with a mask of all bits (or powers of 2) you don't want checked will leave only the bits you want checked.
User avatar
eliw00d
Posts: 585
Joined: Sun Oct 17, 2004 2:46 pm
Location: Duluth, MN
Contact:

Re: CustomInventory "system" question

Post by eliw00d »

DoomRater wrote:AND does a binary AND compare against a number. Since they are all added to each other, the only way to keep them from interfering with each other is to make sure the numbers are all powers of a certain number (2 in this case), and the binary AND with a mask of all bits (or powers of 2) you don't want checked will leave only the bits you want checked.
How would I do it in this case, though? Can you give me an example?
User avatar
DoomRater
Posts: 8270
Joined: Wed Jul 28, 2004 8:21 am
Preferred Pronouns: He/Him
Location: WATR HQ
Contact:

Re: CustomInventory "system" question

Post by DoomRater »

I don't recall the biggest number that it can return, so I don't know off hand. But basically this number minus the flags you want to check for is what you want to AND against the actual CVAR.

dmflags = dmflags AND (max_possible_result - 1048576);

Without knowing what max possible result is, that's the bet I can give you. But this code will always turn the flag you want off.
User avatar
eliw00d
Posts: 585
Joined: Sun Oct 17, 2004 2:46 pm
Location: Duluth, MN
Contact:

Re: CustomInventory "system" question

Post by eliw00d »

DoomRater wrote:I don't recall the biggest number that it can return, so I don't know off hand. But basically this number minus the flags you want to check for is what you want to AND against the actual CVAR.

dmflags = dmflags AND (max_possible_result - 1048576);

Without knowing what max possible result is, that's the bet I can give you. But this code will always turn the flag you want off.
Hmm, I have the latest version of ACC - AFAIK - and it is telling me that I am missing a semicolon.

dmflags = dmflags AND (268435456 - 1048576);

Code: Select all

Original ACC Version 1.10 by Ben Gokey
Copyright (c) 1995 Raven Software, Corp.

This is version 1.47 (Dec 25 2008)
This software is not supported by Raven Software or Activision
ZDoom changes and language extensions by Randy Heit
Further changes by Brad Carney
Even more changes by James Bentler
Some additions by Michael "Necromage" Weber
Error reporting improvements and limit expansion by Ty Halderman
Include paths added by Pascal vd Heiden
Host byte order: LITTLE endian

**** ERROR ****
Line 77 in file "scripts.txt" ...
scripts.txt:77: Missing semicolon.
>  dmflags = dmflags AND
>                      ^
Press any key to continue . . .
User avatar
DoomRater
Posts: 8270
Joined: Wed Jul 28, 2004 8:21 am
Preferred Pronouns: He/Him
Location: WATR HQ
Contact:

Re: CustomInventory "system" question

Post by DoomRater »

Oh durr, I keep thinking this is BASIC.

the symbol for binary AND is &&
User avatar
eliw00d
Posts: 585
Joined: Sun Oct 17, 2004 2:46 pm
Location: Duluth, MN
Contact:

Re: CustomInventory "system" question

Post by eliw00d »

DoomRater wrote:Oh durr, I keep thinking this is BASIC.

the symbol for binary AND is &&
Okay. It spits out a value of 1, which I assumed meant that the flag is indeed on. I changed my if statement for my script to check for dmflags == 1, and it works. However, I turned the flag off and it still comes out as 1...

Is it not supposed to be 1? Or did I do something wrong?

Code: Select all

script 291 (void)
{
	int dmflags = GetCVar("dmflags");
	
	dmflags = dmflags && (268435456 - 1048576);
	
	log(d:dmflags);
	
	if(dmflags == 1)
	{
		SetResultValue(1);
	}
	else
	{
		SetResultValue(0);
	}
}
User avatar
Macil
Posts: 2529
Joined: Mon Mar 22, 2004 7:00 pm
Preferred Pronouns: He/Him
Location: California, USA. Previously known as "Agent ME".
Contact:

Re: CustomInventory "system" question

Post by Macil »

DoomRater wrote:Oh durr, I keep thinking this is BASIC.

the symbol for binary AND is &&
&& is the binary AND operator which returns only true or false. You need to do a bit-wise operation AND, which is &.

Code: Select all

int dmflags = GetCVar("dmflags");
int someflag = dmflags & 1048576;
if(someflag==1048576)
{
  PrintBold(s:"Someflag is on!");
} else {
  PrintBold(s:"Someflag is off!");
}
I think this code looks right.
User avatar
eliw00d
Posts: 585
Joined: Sun Oct 17, 2004 2:46 pm
Location: Duluth, MN
Contact:

Re: CustomInventory "system" question

Post by eliw00d »

Agent ME wrote:
DoomRater wrote:Oh durr, I keep thinking this is BASIC.

the symbol for binary AND is &&
&& is the binary AND operator which returns only true or false. You need to do a bit-wise operation AND, which is &.

Code: Select all

int dmflags = GetCVar("dmflags");
int someflag = dmflags & 1048576;
if(someflag==1048576)
{
  PrintBold(s:"Someflag is on!");
} else {
  PrintBold(s:"Someflag is off!");
}
I think this code looks right.
This one spits out 1048576 with the flag on either on or off, so it's the same situation there.
User avatar
Macil
Posts: 2529
Joined: Mon Mar 22, 2004 7:00 pm
Preferred Pronouns: He/Him
Location: California, USA. Previously known as "Agent ME".
Contact:

Re: CustomInventory "system" question

Post by Macil »

eliw00d wrote:
Agent ME wrote:&& is the binary AND operator which returns only true or false. You need to do a bit-wise operation AND, which is &.
Spoiler:
I think this code looks right.
This one spits out 1048576 with the flag on either on or off, so it's the same situation there.
I just tested the code (in a looping open script):

Code: Select all

script 60 open
{
	int dmflags = GetCVar("dmflags");
	int someflag = dmflags & 1048576;
	if(someflag==1048576)
	{
		PrintBold(s:"Someflag is on!");
	} else {
		PrintBold(s:"Someflag is off!");
	}
	delay(5);
	restart;
}
and it works for me.
(Out of curiosity, why do you need to check the Allow FOV dmflag?)
User avatar
eliw00d
Posts: 585
Joined: Sun Oct 17, 2004 2:46 pm
Location: Duluth, MN
Contact:

Re: CustomInventory "system" question

Post by eliw00d »

Agent ME wrote:(Out of curiosity, why do you need to check the Allow FOV dmflag?)
I'm trying to detect the "Spawn multi. weapons (Coop)" flag, which says it is 1048576.
User avatar
Macil
Posts: 2529
Joined: Mon Mar 22, 2004 7:00 pm
Preferred Pronouns: He/Him
Location: California, USA. Previously known as "Agent ME".
Contact:

Re: CustomInventory "system" question

Post by Macil »

I just checked in zdoom and that flag is 2097152. Where did you read that the flag was that other number?
User avatar
eliw00d
Posts: 585
Joined: Sun Oct 17, 2004 2:46 pm
Location: Duluth, MN
Contact:

Re: CustomInventory "system" question

Post by eliw00d »

Agent ME wrote:I just checked in zdoom and that flag is 2097152. Where did you read that the flag was that other number?
http://zdoom.org/wiki/DMFlags

Hmm. So does that mean the number I found there is actually only half of the actual flag? I changed my code to the following:

Code: Select all

script 291 (void)
{
	int dmflags = GetCVar("dmflags");	
	int smw = dmflags & 2097152;
	
	log(d:smw);
	
	if(smw == 2097152)
	{
		SetResultValue(1);
	}
	else
	{
		SetResultValue(0);
	}
}
And it still doesn't work. My dmflags are set to 263258112, where it should be off.

Actually, I tested it by setting the dmflags to 0 in my launcher and it works, and then changing it to exactly 2097152, and it works there, too. I even changed it to 4194304 to see if a separate flag works, and it reported as 0. Maybe my dmflags are screwy?

EDIT: Well, it can't be my dmflags, I set it to default - where Spawn multi. weapons is on by default - and it reported as 0 and didn't work.

*sigh* This is frustrating.
User avatar
Macil
Posts: 2529
Joined: Mon Mar 22, 2004 7:00 pm
Preferred Pronouns: He/Him
Location: California, USA. Previously known as "Agent ME".
Contact:

Re: CustomInventory "system" question

Post by Macil »

The code works for me. Note than it sets smw = 2097152 when the flag is off, because on is the default.

I think I'll fix the wiki page and check for any other errors. Not sure how it got so wrong.
User avatar
eliw00d
Posts: 585
Joined: Sun Oct 17, 2004 2:46 pm
Location: Duluth, MN
Contact:

Re: CustomInventory "system" question

Post by eliw00d »

Agent ME wrote:The code works for me. Note than it sets smw = 2097152 when the flag is off, because on is the default.

I think I'll fix the wiki page and check for any other errors. Not sure how it got so wrong.
So should I change my results, then? I'm still not sure how to get this to work properly.
User avatar
Macil
Posts: 2529
Joined: Mon Mar 22, 2004 7:00 pm
Preferred Pronouns: He/Him
Location: California, USA. Previously known as "Agent ME".
Contact:

Re: CustomInventory "system" question

Post by Macil »

The script works fine for me. It returns 1 when spawn multi weapons is off, and 0 when it's on. Maybe that's reverse of what you want?
Locked

Return to “Editing (Archive)”