Jump to content




Need Help With If Loop


  • You cannot reply to this topic
5 replies to this topic

#1 subzero22

  • Members
  • 97 posts

Posted 10 October 2013 - 11:23 PM

I posted in the correct forum for peripherals but never got a response and the post below me didn't get a single response since oct 4.

Well anyway is there a way to do a code like this as for some reason the : breaks it but the item I'd requires it.

If Id == 227:3 then
Enter code here
end

How can I do this while still having the : in the code?

Here's link to orriginal post
http://www.computerc...462#entry148462

#2 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

Posted 11 October 2013 - 01:10 AM

Is the ID a string?

#3 Anavrins

  • Members
  • 775 posts

Posted 11 October 2013 - 02:41 AM

In MiscPeripherals, any item that has a damage value get encoded in some way, I've wrote a quick little function to decode it.
function mpDecode(nInput)
	return bit.band(2^15-1, nInput), bit.brshift(nInput, 15)
end

You would use it like this
local id, dmg = mpDecode(numberReturnedByMiscPeripheral)

So for item id "227:3", your code would look like this...
local id, dmg = mpEncode(98531) '-- That is the encoded value of 227:3'
if id == 227 and dmg == 3 then
    '-- Do stuff'
end


#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 11 October 2013 - 06:21 AM

In addition to what Anavrins said... There is also a seed in MiscP which can be changed, as such this is a set of helper functions that NeverCast and I have used in the past.
local itemSeed = 0

function setItemSeed( seed )
  itemSeed = seed
end

function getItemFromUUID( uuid )
  uuid = bit.bxor(uuid, itemSeed)
  local meta = math.floor(uuid/32768)
  local id = uuid % 32768
  return id, meta
end

function getUUIDFromItem( id, meta )
  local uuid = (meta or 0) * 32768 + id
  return bit.bxor(uuid, itemSeed)
end
The usage is the same (except different function names of course)
local id, dmg = getItemFromUUID(98531)
if id == 227 and dmg == 3 then
	--# do stuff
end


#5 subzero22

  • Members
  • 97 posts

Posted 13 October 2013 - 12:00 AM

Well the items I'm listing aren't damage based. Like for example coal is 263 and charcoal is 263:1.

Thanks for the help and I'm assuming the codes will still work for my purposes. If not can you please give example of one that will?

#6 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 13 October 2013 - 12:47 AM

View Postsubzero22, on 13 October 2013 - 12:00 AM, said:

Well the items I'm listing aren't damage based. Like for example coal is 263 and charcoal is 263:1.
That is damage value a.k.a. metadata.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users