Jump to content




Redirect Object Help


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

#1 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 28 November 2014 - 04:20 PM

My redirect object simply is not writing text in the appropriate places, and I wanted to figure out why.

Relevant part
	new.write = function( sText )
		local x,y = new.parent.getCursorPos()
		local px, py = new.getPosition()
		local tx, ty = new.getCursorPos()
		local toWrite = sText--:sub( 1, new.sizex - tx ) --#commented out the sub because it entirely deletes the text... IDK why though.
		new.parent.setCursorPos( px + tx - 1, py + ty - 1 )
		new.parent.setTextColor( new.tColor )
		new.parent.setBackgroundColor( new.bColor )
		new.parent.write( toWrite )
		new.setCursorPos( tx + #tWrite, ty )
	end


#2 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 28 November 2014 - 04:52 PM

I have a guess as to why your sub is 'deleting' text. You're subtracting tx (current cursor pos) from new.sizex. If your new size is smaller than your cursor pos, you're going to end up with a negative value for your sub. I'm guessing you want to actually subtract the difference in size from either the new size or the cursor pos...or something similar? Apologies if I'm off-base with this.

#3 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 28 November 2014 - 05:30 PM

I'm trying to not draw text outside the window's right edge. The cursor shouldn't be outside the window.

I'm thinking that problem is caused by some other problem somewhere, because it doesn't work even with that part commented out.

#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 28 November 2014 - 08:51 PM

Well, this is getting nowhere so I'll post the entire code...

Spoiler


#5 Bomb Bloke

    Hobbyist Coder

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

Posted 29 November 2014 - 01:41 AM

Shot in the dark guess, as you haven't exactly specified how this is failing, but that "tWrite" typo may well have something to do with it.

#6 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 29 November 2014 - 02:21 AM

also a lot of these from what I can see could just be using the parent.

and your parent could just be done with metatables, take this example which overrides a single function in the term and leaves everything else to use the last term (definitely better that writing all the functions)
local oldTerm = term.current()
local newTerm = setmetatable({
  setTextColor = function( c )
    --# pretend some validation is performed here
    oldTerm.setTextColor( c )
  end;
}, oldTerm)
newTerm.setTextColour = newTerm.setTextColor --# the EN_UK/AU version override too

--# redirect will accept the object as the old functions (with the exception of setting the text colour) can be invoked
term.redirect(newTerm)
I have used this technique in CCTicTacToe

#7 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 29 November 2014 - 03:14 AM

Alright, this time my internet connection will not eat my reply.

Here's everything.

icemain

test

.test

Result

Edit: The icon system is bugged, pay no attention to the astrisk in the picture: It has no relevance.

Edited by KingofGamesYami, 29 November 2014 - 03:15 AM.


#8 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 02 December 2014 - 06:11 PM

Anyone have any insights into this?

#9 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 02 December 2014 - 07:58 PM

I'll take a look, but a better description would be helpful. If it's not writing "in the right place", where is it writing?

#10 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 02 December 2014 - 08:35 PM

View PostLyqyd, on 02 December 2014 - 07:58 PM, said:

I'll take a look, but a better description would be helpful. If it's not writing "in the right place", where is it writing?

The post above my last post has a spoiler named "Result" showing exactly what the entire thing is doing at this point: It should be clearing a small portion of the screen below the '.test' toolbar thingy, then printing some text. It is only clearing one line, and refusing to do anything to the rest.

Edit: Here's the spoiler

View PostKingofGamesYami, on 29 November 2014 - 03:14 AM, said:

Result

Edited by KingofGamesYami, 02 December 2014 - 08:38 PM.


#11 Bomb Bloke

    Hobbyist Coder

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

Posted 03 December 2014 - 03:05 AM

I think you're going to have to bite the bullet, hook up an external monitor, and start writing debug info to that - what is the "write" function attempting to write, what is the text length, which co-ords are being targeted, etc? What screen size is the "clear" function detecting? etc... There are presumably some unexpected values coming in from somewhere, but you'll first have to work out the "where" before you can figure out the "why".

I'd also consider sticking an os.pullEvent("char") into the write function so that you can better track exactly what's happening as it happens.

#12 Bomb Bloke

    Hobbyist Coder

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

Posted 03 December 2014 - 05:43 AM

Oh, and here's something else worth considering - the script may be crashing.

For whatever reason, Dan rigged the window API (the one used by every advanced computer to render pretty much everything since CC 1.6 dropped, by way of multishell) to occasionally move the cursor out of bounds. Which means that if a script happens to error while it's out there, you won't see the contents of the error message.

So let's say, for example, you didn't bother to fix that typo I pointed out to you earlier - as soon as you try to get the length of a nil object, the whole thing'll crash, and thanks to the window API you may not see the error message.

If, on the other hand, you DID fix that, then you might consider randomly dotting term.setCursorPos(1,1) lines through your script (so that if it's still crashing, you've got a better chance of having the message rendered somewhere visible).





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users