Jump to content




Attempt to index a Boolean value...?


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

#1 OmegaVest

  • Members
  • 436 posts

Posted 22 February 2013 - 04:33 AM

Okay, so I'm trying to make a silly API. I call it block, and it is meant to make a peripheral out of any block, including turning redstone on and off, and throwing an activation event if the block activates without computer intervention.

But! In actually using the thing, anytime I try to wrap a block, it tells me the subject line. Wha? Isn't that the whole point of a boolean value?

Anyway, I've spent an hour on this and cannot figure out my mistake. I'm hoping you guys will lend me some fresh eyes.

The API:
Spoiler

The Test Program: (I was in the process of testing the eventQueue system)
Spoiler

I left in all debug prints, so work them out as you wish. And thank you in advance.



QUICK EDIT: The error show up on line 1 of the test program, but I'm certain it has something to do with the API.

#2 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 22 February 2013 - 04:39 AM

Have you ever used coroutines before? Nevermind, I'll help with that later if I still have to. But why is block.wrap a boolean? Let me think...

#3 OmegaVest

  • Members
  • 436 posts

Posted 22 February 2013 - 04:47 AM

Not really, this is kinda my experiment with them, and I'm betting I've done something wrong.




!
Oh. Hang on.

EDIT: Nope, still no idea. Going to dig through forums again. (Didn't help the first time, but eh.)

#4 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 22 February 2013 - 04:53 AM

Very odd... Have you reloaded the API? Was there an older version of the API where .wrap was only a bool?

#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 22 February 2013 - 04:55 AM

Well, this definitely won't do what you want it to do regardless. You can create coroutines all day, but there's nothing in that code that causes it to run (except you passing the function to coroutine.create incorrectly). I'm not really sure where the attempt to index boolean is coming from. Are you running this on a fresh computer, loading the API after a clean boot and immediately running the program? If not, you may be dirtying your environment, since you seem to have a propensity for not using local.

#6 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 22 February 2013 - 04:58 AM

I don't know what's wrong with indexing .wrap, but I know that the first time you successfully call it, it'll make the computer freeze. coroutine.create requires a function for the first parameter, and Lua won't pass .blockEvent but call it, and there's an infinite loop inside .blockEvent. Gimme a sec and I post a code that REALLY DOES something with coroutines :D

#7 OmegaVest

  • Members
  • 436 posts

Posted 22 February 2013 - 05:00 AM

@Lyqyd Ha, yeah I don't like local very much. I'm getting better at it. And I tested it on a fresh computer, but it still gives me that.

And, okay, what line am I missing that is supposed to help with that?




View PostLBPHacker, on 22 February 2013 - 04:53 AM, said:

Very odd... Have you reloaded the API? Was there an older version of the API where .wrap was only a bool?

I actually wrote wrap sans coroutine in my head before I ever put it to paper, so to speak.




By the way, this was meant as pre-alpha code. I wasn't sure it would work, since it is kinda outside my comfort zone.
Also, this whole thing came about as a way to end a debate with immibis that has since lapsed into nothing anyway.

#8 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 22 February 2013 - 05:04 AM

Oh, wait a minute. I've got used to my own multitask OS and I thought that this would be easy... You'd need to make a separate "thread" (ok, coroutine) for .blockEvent (just like ComputerCraft does for rednet.run), but that's hard if you can't add coroutines to the main parallel.waitForAny's coroutine list in bois.lua...

#9 OmegaVest

  • Members
  • 436 posts

Posted 22 February 2013 - 05:07 AM

View PostLBPHacker, on 22 February 2013 - 05:04 AM, said:

...(just like ComputerCraft does for rednet.run)...


. . . I'm not above stealing code until I can figure it out. That one parenthetical is actually much more useful than the entire coroutine section on the wiki.

#10 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 22 February 2013 - 05:11 AM

Let me tell you something. Coroutines are about time-sharing. When you create a coroutine (coroutine.create), you get an identifier (tostring calls it a thread), which you can use to resume (and of course, to start) the coroutine you've previously created. (coroutine.resume(cr)) But when you resume a coroutine, the code where you've called coroutine.resume from won't continue running, but will wait until the resumed coroutine returns or yields. (coroutine.yield()) os.pullEventRaw is a big coroutine.yield, therefore so are os.pullEvent and sleep.

#11 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 22 February 2013 - 05:19 AM

View PostOmegaVest, on 22 February 2013 - 05:07 AM, said:

That one parenthetical is actually much more useful than the entire coroutine section on the wiki.

BTW :D Have you ever seen this bunch of code before?

-- Run the shell
local ok, err = pcall( function()
	parallel.waitForAny(
		function()
			os.run( {}, "rom/programs/shell" )
		end,
		function()
			rednet.run()
		end )
end )

Yep, this is from bios.lua...

#12 OmegaVest

  • Members
  • 436 posts

Posted 22 February 2013 - 05:24 AM

Hmm. This will take a bit more planning than normal. Just as much research, but I haven't had to write an outline for a program since high school. That was nearly a decade ago. Crap.




EDIT: Alright, this doesn't need a new post, so I'm updating this one. I figured out what went wrong with the program. It wasn't coroutine, but a small mistake elsewhere. (forgot what part, it was late at night when I fixed it).





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users