- Sky
- Blueberry
- Slate
- Blackcurrant
- Watermelon
- Strawberry
- Orange
- Banana
- Apple
- Emerald
- Chocolate
- Charcoal
Quelfyre
-
Content Count
4 -
Joined
-
Last visited
Posts posted by Quelfyre
-
-
1 hour ago, payonel said:
`io.read()` returns a string, and you want a number, there is a core lua function to convert strings to numbers: `tonumber(string): number`
so something like:
`local num = tonumber(io.read())`
would be fine
note that tonumber returns nil when the input can't be converted.
Also, I strongly recommend you get in the habbit of declaring everything local, unless you are intended to modify the global state of the operating system, and future scripts that you run, at least until the next time you boot. Thus:
local component = require("component") local sides = require("sides") local ingot_mb = 144 local nugget_mb = 16 local block_mb = 1296 while true do local arg = io.read() if not arg or arg == "end" then break end local num = tonumber(arg) if num then component.transposer.transferFluid(sides.south, sides.north, num) else print("could not understand", arg) end end
thanks, this works with numerical values, but the program isn't reading the variables right, if i input ingot it skips straight to "could not understand" do i need to place the variable values somewhere else in the code, or is there some other way i have to do this. but at least i have a working prototype, so thanks!
after replacing arg with num in the print section, it now reads "could not understand nil" so, that means that it isn't recognizing that ingot = 144 right?
-
11 minutes ago, Michiyo said:
When writing a script you have to require the component library with
component = require("component")
When running code directly from the Lua interpreter this line isn't needed.
yay, progress! thanks, i added that to the top but now i get this
so as far as i can tell it's either mistaking the "amnt" variable for a string, or I didn't set up my variables right
-
I'm new to lua, so forgive me if i'm being stupid.
I'm trying to write a program that will let me transfer specific amounts of fluid from one tank to another using a transposer. Ideally I would be able to input "ingot" measurements instead of buckets, ex. Ingot = 144mb, nugget = 16mb, etc. but it won't work, I've uploaded what little code i have and the error message it gives back, p.s. I'd also like to have the program repeat until i input something like "end"
fluid transfer program
in Programming
Posted
thank you for all of your help, looking back over this i might as well have posted this in requests.