Easy-To-Use ComputerCraft Support?

casilleroatr

New Member
Jul 29, 2019
1,360
0
0
Excited about the computercraft support for your mods!

Not sure exactly what you mean with your question so I am making an assumption. Feel free to ignore if the assumption turns out wrong (in which case what is wrong with the formatting?)

You can always wrap your peripherals like so (assuming its on the right hand side of the computer for now). Makes it easier to call peripheral functions.

Code:
local rotaryMachine = peripheral.wrap("right")

local slotData = rotaryMachine.getSlot(0)
--is the return a table or a string?
for i,v in pairs(slotData) do print(i..": "..v) end
That might not work properly inside the Lua shell (putting it in a do end block might help there though)

[/assumption]
 

Reika

RotaryCraft Dev
FTB Mod Dev
Sep 3, 2013
5,079
5,331
550
Toronto, Canada
sites.google.com
Excited about the computercraft support for your mods!

Not sure exactly what you mean with your question so I am making an assumption. Feel free to ignore if the assumption turns out wrong (in which case what is wrong with the formatting?)

You can always wrap your peripherals like so (assuming its on the right hand side of the computer for now). Makes it easier to call peripheral functions.

Code:
local rotaryMachine = peripheral.wrap("right")

local slotData = rotaryMachine.getSlot(0)
--is the return a table or a string?
for i,v in pairs(slotData) do print(i..": "..v) end
That might not work properly inside the Lua shell (putting it in a do end block might help there though)

[/assumption]
It returns a table. In the case of getSlot, it is [itemID][metadata][stackSize][displayName]. My concern is, how will a program actually parse and use this?
 
Last edited:

casilleroatr

New Member
Jul 29, 2019
1,360
0
0
It returns a table. In the case of getSlot, it is [itemID][metadata][stackSize][displayName]. My concern is, how will a program actually parse and use this?
I'm not yet familiar enough with your mods to know what sorts of programs one might make for rotarycraft blocks. But the stackSize and displayName variables will most likely be very useful. So long as the keys in the table have decent, consistent string names it will probably be really easy to use. I have used similar openperipherals methods that return a very similar table to your getSlots method, and I have had no problem using those and some of the programs I made were quite useful, so I expect there will be plenty of uses for your methods.
 

Reika

RotaryCraft Dev
FTB Mod Dev
Sep 3, 2013
5,079
5,331
550
Toronto, Canada
sites.google.com
I'm not yet familiar enough with your mods to know what sorts of programs one might make for rotarycraft blocks. But the stackSize and displayName variables will most likely be very useful. So long as the keys in the table have decent, consistent string names it will probably be really easy to use. I have used similar openperipherals methods that return a very similar table to your getSlots method, and I have had no problem using those and some of the programs I made were quite useful, so I expect there will be plenty of uses for your methods.
Keys in the tables...? Tables are basically arrays, correct?
 

casilleroatr

New Member
Jul 29, 2019
1,360
0
0
Keys in the tables...? Tables are basically arrays, correct?
Yes. Something ideal for the table returned by getSlot written out in Lua would look like this

Code:
slotReturn = {
  ["id"] = id,
  ["metadata"] = metadata,
  ["stackSize"] = stackSize,
  ["itemName"] = itemName,
  }
Parsing that would be fine.
 

Reika

RotaryCraft Dev
FTB Mod Dev
Sep 3, 2013
5,079
5,331
550
Toronto, Canada
sites.google.com
Yes. Something ideal for the table returned by getSlot written out in Lua would look like this

Code:
slotReturn = {
  ["id"] = id,
  ["metadata"] = metadata,
  ["stackSize"] = stackSize,
  ["itemName"] = itemName,
  }
Parsing that would be fine.
How do I do that? All the CC API asks me for is to return an array of objects, in this case three integers and a string.
 

casilleroatr

New Member
Jul 29, 2019
1,360
0
0
How do I do that? All the CC API asks me for is to return an array of objects, in this case three integers and a string.
I'm sorry I don't know I haven't made a mod, just someone who likes to play. Maybe someone from the open peripherals team could help because some of their table returns have string keys.
 

casilleroatr

New Member
Jul 29, 2019
1,360
0
0
This is though CC directly, but OK.
Sorry, do you mean you want to use the Lua in computercraft to look through the table in a computercraft program? If so then it is done this way. Just make a new program and do something like this

Code:
local  rotaryCraftMachine = peripheral.wrap("right")
local slotData =  rotaryCraftMachine.getSlot(0)

--print the whole table out by key and value using generic for loop. Key is stored in i and value in v
for i,v in pairs(slotData) do
  print(i..": "..v) -- .. is concatenate in Lua. Will print out something that looks like this, itemName: steel, but for each key value pair in the table
end

--store the different parts of the table as variables (assuming key names are what I put in the previous post. They can obviously be corrected.) Keys go inside square brackets

local slotID = slotData["id"]
local slotMeta = slotData["metadata"]
local slotStack = slotData["stackSize"]
local slotItem = slotData["itemName"]

--You can do whatever you want with those variables.
I thought you were asking for about the api for modders to add peripherals to computercraft which I know nothing about
 

kittle

New Member
Jul 29, 2019
229
0
0
How do I do that? All the CC API asks me for is to return an array of objects, in this case three integers and a string.
If your just returning an array of objects.. return a 2 column array
{
[ "itemID", 30761],
[ "metadata", 42],
["stackSize", 64],
["displayName", "Yeast"]
}

This has the nice feature to be (almost) infinitely extensible so you dont have to revamp your API if you want to return more or less items
 

Reika

RotaryCraft Dev
FTB Mod Dev
Sep 3, 2013
5,079
5,331
550
Toronto, Canada
sites.google.com
If your just returning an array of objects.. return a 2 column array
{
[ "itemID", 30761],
[ "metadata", 42],
["stackSize", 64],
["displayName", "Yeast"]
}

This has the nice feature to be (almost) infinitely extensible so you dont have to revamp your API if you want to return more or less items
Now to see if CC accepts this as a valid return.

Answer: No.
Code:
computercraft: Could not convert object of type [Ljava.lang.Object; to LuaValue
 
Last edited:

Reika

RotaryCraft Dev
FTB Mod Dev
Sep 3, 2013
5,079
5,331
550
Toronto, Canada
sites.google.com
Maybe it would prefer a Map of strings and doubles/strings? That's the sense I get from looking around https://github.com/OpenMods/OpenPeripheral/tree/master/src/openperipheral/converter.
Again, this is CC directly. Also, the javadoc says this:
Code:
Returns:
An array of objects, representing values you wish to return to the lua program.
Integers, Doubles, Floats, Strings, Booleans and null be converted to their corresponding lua type.
All other types will be converted to nil.
You may return null to indicate no values should be returned.
 

Niels Henriksen

New Member
Jul 29, 2019
502
0
1
Is it your mod that need to return data to CC so the user can read it? Then you just make an array and in each field in the array you put the object. Your object can contain all datatypes that CC accepts. You dont need to use Lua in your mod.
 

Reika

RotaryCraft Dev
FTB Mod Dev
Sep 3, 2013
5,079
5,331
550
Toronto, Canada
sites.google.com
Is it your mod that need to return data to CC so the user can read it? Then you just make an array and in each field in the array you put the object. Your object can contain all datatypes that CC accepts. You dont need to use Lua in your mod.
Yes, I know that - that is what I am doing. The problem is one of usability of the data. A pile of unlabeled numbers is not user-friendly.
 

Niels Henriksen

New Member
Jul 29, 2019
502
0
1
Yes, I know that - that is what I am doing. The problem is one of usability of the data. A pile of unlabeled numbers is not user-friendly.
Then you need to make one more property in your object that tells what this is (like Name or something like that). An API is not supposed to be user-friendly becuase its only data.
 

Niels Henriksen

New Member
Jul 29, 2019
502
0
1
??
Are you suggesting alternating the data with Strings that label them? That is no more user-friendly.
Im not so experinced in Java yet and are only now learning to make MC mods but there is what I will do (psodu code and I will expect it to be like this)

a = new array()
b = new class_of_object()
b.itemID = 30761
b.metadata = 42
b.stackSize = 64
b.displayName = "Yeast"

a.append(b)

Then you only need to return a (the array) to CC. CC will then in Lua return

{
[ "itemID", 30761],
[ "metadata", 42],
["stackSize", 64],
["displayName", "Yeast"]
}