Jump to content




Function ending right away

lua

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

#1 NocturnalDanger

  • Members
  • 8 posts

Posted 14 June 2016 - 07:09 PM

So I have this code:
http://pastebin.com/9jMNw83s

and when I run it, it seems to work fine. However when I select an output (basically every button on screen) it goes to the function continue(), but after the os.sleep it goes right back to main screen.

Before I had:
local function continue()
	--Set up monitor for function
	mon.clear()
	mon.setTextColor(colors.red)
	mon.setCursorPos(18,13)
	mon.write("Touch here to continue.")
mon.setCursorPos(14,27)
mon.write("Touch here to add another fluid")
	os.sleep(2) --Pause to avoid double-tap
	if xPos >= 18 and xPos <= 40 and yPos == 13 then --Test for touch here
	   redstone.setBundledOutput("top", 0) --Stop Redstone
	end
end

And the problem started after I changed it to:
local function continue()
	--Set up monitor for function
	mon.clear()
	mon.setTextColor(colors.red)
	mon.setCursorPos(18,13)
	mon.write("Touch here to continue.")
mon.setCursorPos(14,27)
mon.write("Touch here to add another fluid")
	os.sleep(2) --Pause to avoid double-tap
	if xPos >= 18 and xPos <= 40 and yPos == 13 then --Test for touch here
	   redstone.setBundledOutput("top", 0) --Stop Redstone
	redstone.setBundledOutput("right", 0) --Stop Redstone
	redstone.setBundledOutput("left", 0) --Stop Redstone
	redstone.setBundledOutput("back", 0) --Stop Redstone
elseif xPos >= 14 and xPos <= 44 and yPos == 27 then --Test for touch here
	-- Straight to end of continue(), to select new fluid.
	end
end

I tried getting rid of the os.sleep (By making it a comment (--os.sleep)) and the monitor didnt do anything. (or it went straight to the main screen again, without the pause.)

Any Ideas? Should I declare the event before I declare the function? (Actually, Ill try that now)

EDIT: No improvement on declaring the event sooner. It doesnt leave the function right away, but it doesnt actually leave continue() at all.

Edited by NocturnalDanger, 14 June 2016 - 07:18 PM.


#2 The_Cat

  • Members
  • 119 posts

Posted 14 June 2016 - 10:02 PM

So, when you click on the monitor on the main screen you go to the continue() screen then it immediately goes off it / doesn't wait for the second input? If so the reason it doesn't wait for the input is because you are not asking for it, you are checking the xPos and yPos from the previous touch. (Check how the first main screen works for touching and implement it for the continue function. Hint: os.pullEvent("monitor_touch"))

Edited by The_Cat, 14 June 2016 - 10:02 PM.


#3 NocturnalDanger

  • Members
  • 8 posts

Posted 14 June 2016 - 10:53 PM

View PostThe_Cat, on 14 June 2016 - 10:02 PM, said:

So, when you click on the monitor on the main screen you go to the continue() screen then it immediately goes off it / doesn't wait for the second input? If so the reason it doesn't wait for the input is because you are not asking for it, you are checking the xPos and yPos from the previous touch. (Check how the first main screen works for touching and implement it for the continue function. Hint: os.pullEvent("monitor_touch"))

I have an os.pullevent on line 56. And thats before most of the code. (It shouldnt need to be before I decalre a function, but I tried it and it still didnt work.)

I gave the link to the pastebin on the very top of the post, if you missed it, take a look. (everything is done by me, if you have a way to clean it up, let me know. I fixed allot of the indentations on my computer but I didnt reupload it.)

Edited by NocturnalDanger, 14 June 2016 - 10:54 PM.


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 15 June 2016 - 12:06 AM

View PostNocturnalDanger, on 14 June 2016 - 10:53 PM, said:

I have an os.pullevent on line 56.

But you don't have one in your "continue" function, after having told the user to "Touch here to continue". That function pauses a couple of seconds (due to the sleep) and then near-instantly returns; at which point your main loop wipes the screen and redraws it again.

At every point where you want your script to halt and wait for an event, you have to tell it to halt and wait for an event (eg, by calling os.pullEvent() again).

#5 NocturnalDanger

  • Members
  • 8 posts

Posted 15 June 2016 - 04:45 AM

View PostBomb Bloke, on 15 June 2016 - 12:06 AM, said:

View PostNocturnalDanger, on 14 June 2016 - 10:53 PM, said:

I have an os.pullevent on line 56.

But you don't have one in your "continue" function, after having told the user to "Touch here to continue". That function pauses a couple of seconds (due to the sleep) and then near-instantly returns; at which point your main loop wipes the screen and redraws it again.

At every point where you want your script to halt and wait for an event, you have to tell it to halt and wait for an event (eg, by calling os.pullEvent() again).

Well lines 59 through 209 work fine, even though I dont have it 48 times. I assumed that since Im calling the function within those lines too, that it shouldnt need it.

EDIT: So I put on in my continue function and it works (Thank you) But I envisioned when you click "Add another fluid" that it would keep the redstone signal active (On both outputs), however when you select a new output it shuts the old one off.

WHICH isnt an issue, but its something that works differently than expected. And I was wondering why. (Honestly, if its super simple, Ill change it, because thats adds an ability to "cross out" or "cover" active signals which would make alloying easier. But if its allot of work I just wont mess with it.)

EDIT2: My updated code is pastebin.com/QcghX0xa

Edited by NocturnalDanger, 15 June 2016 - 06:15 AM.


#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 15 June 2016 - 06:36 AM

The idea is that setBundledOutput doesn't toggle colours; rather it sets a specific combination of colours to be active or inactive. If you specify the colour red, then you get only red; if you later specify black, then red disables and black activates. If you want both at once you have to request both at once.

Really what's going on is that every colour is represented by a number; a power of two. Getting a "combination of colours" is hence as easy as adding those numbers together (or more accurately, ORing them together).

This is where the functions in the colours API come in handy. Eg, if you want to enable the colour red on a given side, without affecting the other colours already enabled there and regardless as to whether red is already enabled, you might do:

rs.setBundledOutput("left", colours.combine(rs.getBundledOutput("left"), colours.red))

Edited by Bomb Bloke, 15 June 2016 - 06:36 AM.


#7 NocturnalDanger

  • Members
  • 8 posts

Posted 15 June 2016 - 07:13 AM

View PostBomb Bloke, on 15 June 2016 - 06:36 AM, said:

The idea is that setBundledOutput doesn't toggle colours; rather it sets a specific combination of colours to be active or inactive. If you specify the colour red, then you get only red; if you later specify black, then red disables and black activates. If you want both at once you have to request both at once.

Really what's going on is that every colour is represented by a number; a power of two. Getting a "combination of colours" is hence as easy as adding those numbers together (or more accurately, ORing them together).

This is where the functions in the colours API come in handy. Eg, if you want to enable the colour red on a given side, without affecting the other colours already enabled there and regardless as to whether red is already enabled, you might do:

rs.setBundledOutput("left", colours.combine(rs.getBundledOutput("left"), colours.red))

So if I have black active, and I then run
rs.setBundledOutput("left", colours.combine(rs.getBundledOutput("left"), colours.red))
Itll ADD red, so then both black and red are active?

getBundledOutput lists the active colors and then adds red to them, it seems.

(Sorry, my programming knowledge is limitted to CSS, HTML, some Java, some C++ and LabView(Sadly)), used to know Python. So this is a whole new world to me.)

EDIT: Would this mess work?

	    redstone.setBundledOutput("left", colors.combine(colors.combine(redstone.getBundledOutput("left"), redstone.getBundledOutput"right"), colors.combine(getBundledOutput("back"),colors.red)))

Edited by NocturnalDanger, 15 June 2016 - 07:48 PM.


#8 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 16 June 2016 - 03:37 AM

View PostNocturnalDanger, on 15 June 2016 - 07:13 AM, said:

So if I have black active, and I then run
rs.setBundledOutput("left", colours.combine(rs.getBundledOutput("left"), colours.red))
Itll ADD red, so then both black and red are active?

That's what I said, yes.

View PostNocturnalDanger, on 15 June 2016 - 07:13 AM, said:

EDIT: Would this mess work?
redstone.setBundledOutput("left", colors.combine(colors.combine(redstone.getBundledOutput("left"), redstone.getBundledOutput"right"), colors.combine(getBundledOutput("back"),colors.red)))

Well, no, you're missing too many brackets, along with a few other characters.

It looks like you meant:

rs.setBundledOutput("left", colours.combine(rs.getBundledOutput("left"), rs.getBundledOutput("right"), rs.getBundledOutput("back"), colours.red))

... though even then I'm suspecting you meant to use some "rs.getBundledInput"s in there instead.

#9 NocturnalDanger

  • Members
  • 8 posts

Posted 16 June 2016 - 04:38 AM

View PostBomb Bloke, on 16 June 2016 - 03:37 AM, said:

rs.setBundledOutput("left", colours.combine(rs.getBundledOutput("left"), rs.getBundledOutput("right"), rs.getBundledOutput("back"), colours.red))

... though even then I'm suspecting you meant to use some "rs.getBundledInput"s in there instead.


Yes, thank you.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users