How to know what previous flags compose a final flag?
#1

Hi. I'm working with item flags for first time, I know this flag (134217758) was made with this previous flags sum:

1 << 1;    // 2

1 << 2;    // 4

1 << 3;    // 8

1 << 4;    // 16

1 << 27; // 134217728

Sum of all results = 134217758

Now, how i can revert the final flag (134217758) to get 27, 4, 3, 2 and 1?

#2

2



I know that in C# it can be done with the following code

for (int index = 0; index < 64; ++index)
ClbItemFlag.SetItemChecked(index, (flag & 1L << index) > 0L);

But I want to do it in lua and I don't understand exactly how this code works... Obviously This: "(flag & 1L << index) >" 0L Is returning a boolean, but I don't understand why it returns a bool...

P.S: And yes, if anyone asks, I don't know exactly what I'm doing...

#3

#Solved

#4

Post your solution so other people can look it up if needed.

#5
tblFlags = {
"Count",
"Drop",
"Upgrade",
"Exchange",
"Sell(NPC)",
"Not Delete",
"Made",
"Mix",
"Cash",
"Lord",
"No Stash",
"Change",
"Composite",
"Duplication",
"lent",
"Rare",
"ABS",
"Not Reform",
"ZoneMove Del",
"Purple Seals",
"Trigger",
"Raid Special",
"Quest",
"LuckyDraw Box",
"Not TradeAgent",
"Durability",
"Costume2",
"Socket",
"Seller",
"Castillan",
"LetsParty",
"Non-RVR",
"Quest Give",
"Toggle",
"Compose",
"NotSingle",
"Invisible Custom",
"37",
"38",
"39",
"40",
"41",
"42",
"43",
"44",
"45",
"46",
"47",
"48",
"49",
"50",
"51",
"52",
"53",
"54",
"55",
"56",
"57",
"58",
"59",
"60",
"61",
"62",
"63"
};

local FlagPicker = 60; -- Your flag

for i = 0, #tblFlags do
local Flag = 1*2^i; -- Left shift iteration num by 1

if(FlagPicker % (Flag + Flag) >= Flag)then
-- true
else
-- false
end
end

 



Forum Jump:


Users browsing this thread: 1 Guest(s)