Jump to content




Printing ccSensor data on monitor


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

#1 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 04 November 2012 - 02:27 AM

Hey everyone, I have a program that gets reading's of MFSU, stores it and prints it on a monitor. But it always print decimal number.

For example:

I have it to count how many MFSU's, MFE's and BatBoxes there are around the sensor and it works great but the text on the monitor is different to the screen:

Pictures
Spoiler

How do I change it so it doesn't do that :S

#2 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 04 November 2012 - 03:49 AM

just string.sub(val,-2) to cut out the last 2 digits

#3 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 04 November 2012 - 07:08 AM

In my code I converted the strings into numbers, would string.sub still work with numbers? Will test it later :D/>

#4 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 04 November 2012 - 09:55 AM

it should auto convert them back onto strings and shorten them

#5 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 08 November 2012 - 06:56 AM

Sorry for late reply :D/> Well that works thanks :P/>

Now another quest, the total value for EU is also failing:

Pictures
Spoiler

How do I make the numbers show properly?

#6 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 08 November 2012 - 07:32 AM

please post your code

#7 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 08 November 2012 - 07:34 AM

Spoiler


#8 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 08 November 2012 - 10:12 AM

I see... I think it is just converting the number into scientific notation to decrease the size of the number. try

monW(11, 11, tostring(total_max_storage))

as the print function converts the parameter to string before writing to the screen, it is displaying correctly but the monitor is not. just give the monitor what print converts it to and they will hopefully be identical. to be honest with you I am not hopeful on that count but here is one that should work fine

local function convert(num)
  local temp=num
  local count=0
  while temp%10==0 do
	count=count+1
	temp=temp/10
  end
  return temp..string.rep('0',count)..' '
end

monW(11, 11, convert(total_max_storage))
monW(11, 14, convert(total_curr_storage))

another thing that is just me being my usual irritating self:

for your monitor writing at CDS function I would recommend returning the cursor to the original position after writing

function monW(x, y, str)
  local cur={mon.getCursorPos()}
  mon.setCursorPos(x, y)
  mon.write(str)
  mon.setCursorPos(unpack(cur))
end


#9 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 08 November 2012 - 10:56 AM

monW(11, 11, tostring(total_max_storage))

This works :DD Thanks man!





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users