Closed hzFishy closed 1 year ago
You probably want the extract method
I'd really recommend having a read through the doc comments in that file. They (hopefully) explain the core API pretty well.
I searched how the items.extract works and the link with https://github.com/SquidDev-CC/artist/blob/4234f9de124e9b1b8db020c24ce50593cdcd5173/src/artist/gui/interface/turtle.lua#L90 AND https://github.com/SquidDev-CC/artist/blob/4234f9de124e9b1b8db020c24ce50593cdcd5173/src/artist/gui/interface.lua#L6
but I don't know how to link all together to my custom module without crashing anything :/
Can you post your code and what error you're getting?
Can you post your code and what error you're getting?
I don't have any specific errors because I don't have any specific code. I have tried multiples things but either nothing changed or artist doesn't launch and I have no errors in the term.
It seems that I can't understand the link between the context of your files
Can you post your full code then? I'm assuming you've got something based of the code in https://github.com/SquidDev-CC/artist/issues/26#issuecomment-1370294680 ? Sorry, I just don't think I can really explain anything further without referencing back to something concrete.
Sorry for the late response, here is the "test code" (tbh that doesn't make any sense but I added what I though would be a good start)
_LCDLC_test.lua
located in
please note that I wrote this program 2 days ago, so sometimes i can't re-explain why I did this or this, sorry
-- Those vars are for testing
local name = "minecraft:grass_block"
local count = 4
local displayName = "Grass Block"
--
return function(context) -- I added "return function(context)" because it seems like most of your fct works with this and you used it for the counter custom module: *
local items = context:require "artist.core.items" -- because it used the items file ("items" class)
local turtle_helpers = require "artist.lib.turtle" -- for getting "this_turtle"
local this_turtle = turtle_helpers.get_name() -- for getting "this_turtle"
local gui = require "artist.gui.core" -- i forgot why, was probably testing something
local turtle = context:require "artist.gui.interface.turtle" -- i forgot why, was probably testing something
-- Here i just copy/pasted the code here: **, but I didn't starting editing it because I didn't understand its functioning
items:extract(this_turtle, hash, count, nil,function()turtle_tasks.spawn(function() turtle_pickup(hash) end) end)
end
* https://github.com/SquidDev-CC/artist/issues/26#issuecomment-1370294680 ** https://github.com/SquidDev-CC/artist/blob/4234f9de124e9b1b8db020c24ce50593cdcd5173/src/artist/gui/interface/turtle.lua#L90-L91
There's a couple of possible issues I can see:
hash
isn't defined anywhere, so the call to extract
will error. You probably wanted to use name
here instead.turtle_tasks
isn't defined anywhere, so that function will error when it's called. In this case, you can just remove that whole callback - it's not needed for what you're doing.I think a lot of the issues you're having here are due to the fact that you're not super familiar with Lua. I don't want to put you off working on this project, but really would recommend working on a couple of simpler things first! Artist is a complex project, so hacking on it probably isn't the best place to start.
hash
isn't defined anywhere, so the call toextract
will error. You probably wanted to usename
here instead.turtle_tasks
isn't defined anywhere, so that function will error when it's called. In this case, you can just remove that whole callback - it's not needed for what you're doing.
Thank you for the reports; I will fix them
I think a lot of the issues you're having here are due to the fact that you're not super familiar with Lua. I don't want to put you off working on this project, but really would recommend working on a couple of simpler things first! Artist is a complex project, so hacking on it probably isn't the best place to start.
My project is 95% finished, I am working on it since early december, I don't want to stop it just because of the hard last 5% (which is the extract part)
Hello,
Somehow I made my module work, I only have one problem: how to call when needed.
I saw that your where using the mediator:subscribe
and mediator:subscribe:publish
to send or "wait" a specific event.
I suppose it is possible to add my own, the thing is I don't know where I can corectly add it.
To be simple I want the turtle to check a redstone signal, and when it is at X
it "runs" my module, (I tested using a shell.run
command but it crashs all the artist program)
My Module _LCDLC_test.lua
in /.artist.d/src/
name, count = ...
return function(context)
local items = context:require "artist.core.items"
local turtle_helpers = require "artist.lib.turtle"
local this_turtle = turtle_helpers.get_name()
local function extract()
print(this_turtle, name , count)
items:extract(this_turtle, name , count, 5)
sleep(0.5)
end
context.mediator:subscribe("items.change", extract) -- for testing
end
I tested to execute shell.run("/.artist.d/src/_LCDLC_test.lua", "computercraft:monitor_advanced","17")
from other Artist script like from your moduleCounter
, but it crashs everything
When I say "it crashs everything" i mean:
Do you have any suggestions on how to do this ?
You can't use shell.run
here as that starts a whole new program, which won't have access Artist. I'm not sure why it crashes - I suspect something else is going on there, you'd have to check /.artist.d/log
for the full error.
In order to use multiple files, you're meant to use require
/context:require
instead (just like you use to load the artist.core.items
and artist.lib.turtle
modules). However, in this case I'd just put everything in one file - it's going to be easier than dealing with Lua modules.
In order to subscribe to an event, you can spawn a new thread to run in parallel with everything else and then just do whatever inside that:
context:spawn(function()
while true do
if redstone.getInput("left") then do_something() end
os.pullEvent("redstone")
end
end
Hello, thanks for your answers :)
I have one last question: for some reason when the item is extracted it goes to the turtle inventory, but instantly goes back in, without dropping (auto_drop
is set to true)
For now I am using another turtle to suck all the time, but this is going to be kinda rough to handle because it has to not suck items that are given.
Do you have any ideas on how to solve this ?
Can you not just send the items directly to the other turtle instead?
I am dumb, I forgot that I am not forced to use one turtle ......
Hello :) Sorry for creatign a new issue for this Thanks to you, my project is almost finished, but I face one more problem, and its has the same main issue than the other request i did for the count.
Lets imagine that in the
/src/
folder of.artist.d
I have a file calledextract_stuff.lua
, in this file I have "variables" containing theid
of a item (that exist in the storage) and thecount
of this item requested.(1) Lets say that I already checked that this
item
EXIST and its COUNT is equal or lower than how much there is in the storage.How could I link this
extract_stuff.lua
script with your extraction system ? So I can "request a extraction" of any item with its count like if a player was using the turtle interface ?. I hope that with the (1) statement it is "easy" and possible to do it.Me and my friend working on the project will be very grateful to you if you could do this for us 🙏 If you have any questions please ask then