Jump to content


MysticT's Content

There have been 177 items by MysticT (Search limited from 10-February 22)


By content type

See this member's


Sort by                Order  

#53118 [WIP]Best Program Evaaa!

Posted by MysticT on 24 November 2012 - 07:56 AM in Programs

View Postdlcruz129, on 24 November 2012 - 07:33 AM, said:

Correct usage: shell.run("pastebin", "get", "abc123", "startup")
You may want to check the changes in the newer versions (I can't remember wich one now). You can use it like he did now ;)/>.



#53681 combining strings

Posted by MysticT on 25 November 2012 - 09:44 AM in Ask a Pro

If you want to use the user input, it should be like this:
local filename = read()
filename = filename..".nfp"



#56770 term.clearLine() EVOLVED

Posted by MysticT on 05 December 2012 - 11:53 AM in Suggestions

A slightly shorter version without loops:
local function clearPart(x1, x2, y)
  term.setCursorPos(x1, y)
  term.write(string.rep(" ", (x2 - x1) + 1))
end



#56781 How do I download a binary file?

Posted by MysticT on 05 December 2012 - 12:09 PM in Ask a Pro

Try writing each byte in the string to the file (like suggested above), like this:
local response = http.get("https://www.google.com/images/srpr/logo3w.png")
if response then
  local sResponse = response.readAll()
  response.close()
  local file = fs.open("file.png", "wb")
  for i = 1, #sResponse do
    file.write(string.byte(sResponse, i))
  end
  file.close()
end



#57970 shell.run attemt to call nil

Posted by MysticT on 09 December 2012 - 02:53 PM in Ask a Pro

If the function is inside an api, you can't use the shell api, so that's why it says "attempt to index a nil value" (shell doesn't exist).



#58582 fs.getBase()

Posted by MysticT on 11 December 2012 - 11:56 AM in General

Or this:
function getDir(path)
  return string.sub(path, 1, #path - #fs.getName(path))
end



#65144 [Question]Other programming languages?

Posted by MysticT on 28 December 2012 - 03:43 AM in Ask a Pro

View PostAquilamo, on 28 December 2012 - 03:16 AM, said:

Is there any public information about how ComputerCraft works?
No, there isn't. And even if there were, it wouldn't help you, since it's heavily based on how lua works, using coroutines for each computer.
Writing an entirely new mod would make it easier to write the interpreter (you can use an existing one), but you have to make the mod, including the blocks, items, etc. and all the network handling.
Conclusion: just stick to lua :P



#65146 [1.3 and 1.4][SMP/SSP]fs API acting strange

Posted by MysticT on 28 December 2012 - 03:53 AM in Bugs

When it says computer, it means the CC computer, not your computer :P



#65149 Turtles not working

Posted by MysticT on 28 December 2012 - 03:57 AM in Ask a Pro

Try actually calling the function:
test.test2()
brackets are important, otherwise it will just return the function (the actual function, not it's result).
When you run it, nothing happens because you are not calling the function. Try adding:
test2()
at the end of the file.
Also, if you want to make a program, don't put it in the apis directory, that's for apis. Place it in the programs directory or the root of the computer/turtle.



#65184 Turtles not working

Posted by MysticT on 28 December 2012 - 05:27 AM in Ask a Pro

 TheOriginalBIT, on 28 December 2012 - 03:59 AM, said:

 MysticT, on 28 December 2012 - 03:57 AM, said:

brackets are important, otherwise it will just return the function (the actual function, not it's result).

It actually returns the reference/location in memory to the function, not the function itself.
That's what I meant, just trying to make it clearer for him :P

 Quartiz, on 28 December 2012 - 04:16 AM, said:

 TheOriginalBIT, on 28 December 2012 - 03:55 AM, said:

sounds like you are doing this in the Lua program on the terminals... type test.test2() instead

the reason that it says function: random numbers is not actually an error, it is doing a tostring( ) on the function and actually telling you its reference/location in memory, hence the numbers differing each time :) when this is used in programming intentionally it is called function pointers. :)

hope this helps :)
the thing with the () worked like a charm but i still dont understand why the programs isnt working when i program them directly to the turtle or on a floppy disk, any clue? :P
Like I said before, you need to call the function in the program. It should be something like:
function test2()
  -- do something
end

test2() -- call the function so it actually does something



#65299 CC 1.48 CCReadImage

Posted by MysticT on 28 December 2012 - 12:17 PM in Peripherals and Turtle Upgrades

I've been working a little on reading a bmp since your other thread. I succesfully loaded some bmp images, but it's still a wip. It can load just a few formats and bmp versions, but I'll add support for as many as I can and share it when/if it's ready.



#68713 [Lua][Error]/[Question] How do i unload a File?

Posted by MysticT on 04 January 2013 - 11:04 AM in Ask a Pro

The problem with the api is that you can't use the shell api there. Apis are loaded in an environment where the shell api table is not defined, so it doesn't exist (it's nil, that's why it says attempt to index a nil value).



#68740 [Lua][Error]/[Question] How do i unload a File?

Posted by MysticT on 04 January 2013 - 11:42 AM in Ask a Pro

You can use any loaded api, just that the shell api is not a common loaded api, it is loaded in the shell environment, wich is different from the global one used to load apis.



#69813 CC 1.48 CCReadImage

Posted by MysticT on 06 January 2013 - 06:50 AM in Peripherals and Turtle Upgrades

The map has to use integers as the keys if you want to access it like
table[2][4]
You are using strings right now, so you have to access the values like
table["2"]["4"]
So, this would be java-side:
Map<Integer, Map<Integer, Integer>> map = new TreeMap<Integer, Map<Integer, Integer>>();
for (int x = 0; x < width; x++) {
  Map<Integer, Integer> xMap = new TreeMap<Integer, Integer>();
  map.put(x, xMap);
  for (int y = 0; y < height; y++) {
	xMap.put(y, image.getRGB(x, y) & 0x00FFFFFF)
  }
}
Then you can use it like you wanted in lua:
local rgbValues = imageApi.getValuesRGB()
print("Size: ", #rgbValues)
print("First value: ", rgbValues[1][1])



#69869 BSoD Fail

Posted by MysticT on 06 January 2013 - 09:28 AM in Ask a Pro

View Postnutcase84, on 06 January 2013 - 03:12 AM, said:

Thanks guys. I also have another problem.

x, y, button = getMouseClick()
if x >= xlocation and x <= x1 and y == ylocation then --item1
  shell.run(item1cmd)
end
This does not work. It gives me a nil at shell.run. why?
(I have the getMouseClick function and the item1cmd var.)
Is the code in an api? If it is then that's the problem, you can't use the shell api in an api (there's some posts with an explanation about why this happens).



#70867 Use functions in tables

Posted by MysticT on 08 January 2013 - 01:58 PM in Ask a Pro

You can also define the function inside the table:
action = function() redirect("smartpaste.com/home") end
it works the same way, just saving a few lines.
I would still recommend using the method TheOriginalBIT said in some cases. If you are going to use the same function somewhere else, it's better to define it before and then assign it where needed.



#75354 [Solved] "Non-blocking" os.pullEventRaw()

Posted by MysticT on 16 January 2013 - 02:19 PM in Ask a Pro

That's the way ComputerCraft works, you yield to wait for an event to allow other computers to run. Making an infinite loop that doesn't yield until there's an event wouldn't let other computers work.
Your workaround (starting a timer to fire an event) should work (you could also queue a fake event so it doesn't wait for the timer), but note that it would make computers lag a lot (if there's more than one computer in the world).
Why would you want to do it anyway? there's no need to, you just have to make the "threads" work like that (wait for an event then act accordingly).



#75372 [Solved] "Non-blocking" os.pullEventRaw()

Posted by MysticT on 16 January 2013 - 03:14 PM in Ask a Pro

View PostRunasSudo, on 16 January 2013 - 02:38 PM, said:

I'm not sure you understand what I want to do.
When one of my threads runs coroutine.yield("mouse_click") for example, my API needs to not resume it again until it has pulled a mouse_click event. In the meantime, however, it should still be running other coroutines. This implementation, however, does not let any other coroutines run until it has pulled said event.

I have a window manager that spawns two threads. One updates a clock, and one waits for a mouse_click, then exits the program. With this implementation, it does not run the clock-updating function until an event has been pulled. Not what I want to happen. When I use the parallel API to run both functions at the same time, it works.
Well, you said that you wanted to run the loop even when there's no events:

View PostRunasSudo, on 16 January 2013 - 12:09 PM, said:

EDIT: To clarify, os.pullEventRaw() performs as expected in this code (it blocks), but I don't want it to perform as such.
I want the while true loop to continue regardless of whether an event has been fired.
(Also the topic title is "Non-blocking" os.pullEventRaw()) That's why I said that.
For what I see, that code should work. Can we see the code you use to start the threads and what they run maybe?



#75641 Append to table with key as a string

Posted by MysticT on 17 January 2013 - 05:53 AM in Ask a Pro

In lua, you can add a new value to the table by simply doing:
table[key] = value
So, this should work:
local id, msg = rednet.receive()
idsTable[id] = msg
it would store the last message sent from every id.



#83294 [Question] how to check if a variable is even or odd

Posted by MysticT on 03 February 2013 - 10:04 AM in Ask a Pro

View Postikke009, on 03 February 2013 - 07:42 AM, said:

wonderful job mate. in case you didn't know, the % sign (called modulo) gives you the result of a division stripped of all integers.
so 1 % 4 and 5 % 4 would both yield 0.25
err, not really. It returns the raminder of the integer division. Both 1 % 4 and 5 % 4 would return 1.



#83368 Attempt to index....?

Posted by MysticT on 03 February 2013 - 12:42 PM in Ask a Pro

I think the problem is that fs.list returns a list of the file names inside a directory, so when using io.open you pass the name of the file, instead of the full path.
this should work:
function ReadDir(dir)
 local dateien = fs.list(dir)
 for i = 1, #dateien do
  local path = fs.combine(dir, dateien[i])
  if fs.isDir(path) then
    ReadDir(path)
  end
  check(path)
 end
end



#83530 Attempt to index....?

Posted by MysticT on 04 February 2013 - 04:11 AM in Ask a Pro

There's no lightgreen color:
term.setTextColour(colors.lightgreen)
It should be:
term.setTextColour(colors.lime)



#84406 Cyclic Redundancy Checks (Aka Crc)

Posted by MysticT on 06 February 2013 - 12:26 PM in APIs and Utilities

View PostImgoodisher, on 06 February 2013 - 12:07 PM, said:

Not to mention that that code wont work if
data = {"a", "b", nil, "c"}
(it would loop 2 times, not 3)
Well, that would happen with ipairs too. Not with pairs, but it doesn't iterate in order, so you could get "c", "a", "b" (from your example) or anything.



#91091 LuaJ 3.0

Posted by MysticT on 25 February 2013 - 11:42 AM in Suggestions

This is more like a question than a suggestion, but anyway.
Are there any plans to update LuaJ to 3.0? It has support for lua 5.2, wich would be really nice.
I think it's still in alpha, but I had no troubles with it so far.
Or are you still planing to remove LuaJ and use native libraries? I know this is a requirement to use the pluto library, wich is needed to add persistance.



#91122 LuaJ 3.0

Posted by MysticT on 25 February 2013 - 01:49 PM in Suggestions

Yeah, tought so. It might break some programs. So, even if you do drop LuaJ and use native libraries, it would still be 5.1 right?