CustomInventory "system" question
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.
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.
- DoomRater
- Posts: 8270
- Joined: Wed Jul 28, 2004 8:21 am
- Preferred Pronouns: He/Him
- Location: WATR HQ
- Contact:
Re: CustomInventory "system" question
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.
Re: CustomInventory "system" question
How would I do it in this case, though? Can you give me an example?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.
- DoomRater
- Posts: 8270
- Joined: Wed Jul 28, 2004 8:21 am
- Preferred Pronouns: He/Him
- Location: WATR HQ
- Contact:
Re: CustomInventory "system" question
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.
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.
Re: CustomInventory "system" question
Hmm, I have the latest version of ACC - AFAIK - and it is telling me that I am missing a semicolon.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.
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 . . .
- DoomRater
- Posts: 8270
- Joined: Wed Jul 28, 2004 8:21 am
- Preferred Pronouns: He/Him
- Location: WATR HQ
- Contact:
Re: CustomInventory "system" question
Oh durr, I keep thinking this is BASIC.
the symbol for binary AND is &&
the symbol for binary AND is &&
Re: CustomInventory "system" question
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...DoomRater wrote:Oh durr, I keep thinking this is BASIC.
the symbol for binary AND is &&
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);
}
}
- 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
&& is the binary AND operator which returns only true or false. You need to do a bit-wise operation AND, which is &.DoomRater wrote:Oh durr, I keep thinking this is BASIC.
the symbol for binary AND 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!");
}
Re: CustomInventory "system" question
This one spits out 1048576 with the flag on either on or off, so it's the same situation there.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 &.DoomRater wrote:Oh durr, I keep thinking this is BASIC.
the symbol for binary AND is &&
I think this code looks right.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!"); }
- 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
I just tested the code (in a looping open script):eliw00d wrote:This one spits out 1048576 with the flag on either on or off, so it's the same situation there.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.
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;
}
(Out of curiosity, why do you need to check the Allow FOV dmflag?)
Re: CustomInventory "system" question
I'm trying to detect the "Spawn multi. weapons (Coop)" flag, which says it is 1048576.Agent ME wrote:(Out of curiosity, why do you need to check the Allow FOV dmflag?)
- 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
I just checked in zdoom and that flag is 2097152. Where did you read that the flag was that other number?
Re: CustomInventory "system" question
http://zdoom.org/wiki/DMFlagsAgent ME wrote:I just checked in zdoom and that flag is 2097152. Where did you read that the flag was that other number?
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);
}
}
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.
- 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
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.
I think I'll fix the wiki page and check for any other errors. Not sure how it got so wrong.
Re: CustomInventory "system" question
So should I change my results, then? I'm still not sure how to get this to work properly.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.
- 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
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?