Jump to content


rockymc's Content

There have been 7 items by rockymc (Search limited from 29-March 23)


By content type

See this member's

Sort by                Order  

#218691 string.format("%.3f") not formatting float object

Posted by rockymc on 25 May 2015 - 09:21 PM in Bugs

I was messing with a program I made, when I realized that when I tried to format a float, the float wouldn't format.

Then, I opened the in-game lua and typed this
print(string.format("%.3f", 3.14159))
And the result was 3.14159 instead of 3.141 (3.142 because it rounds the number).

Is it a known issue? What can I do to fix it?



#218676 Colored text in terminal

Posted by rockymc on 25 May 2015 - 07:39 PM in Ask a Pro

Okay, I've been rewriting the program, and I came across a problem.

I'm using string formatting to format a big float number to 3 decimal cases. However, it doesn't work, and I even tried using the lua command. Here's what you need to try:

print(string.format("%.3f", 3.14159))

Am I the only one with this problem (formatting doesn't work)?



#218563 Colored text in terminal

Posted by rockymc on 24 May 2015 - 09:10 PM in Ask a Pro

This is the round function:
local function round(num, dec)
  local shift = 10^(dec or 2)
  return math.floor(num * shift + 0.5) / shift
end

Found it somewhere here.

@Lyqyd: thanks for merging them.



#218478 Colored text in terminal

Posted by rockymc on 24 May 2015 - 02:04 PM in Ask a Pro

The error message that I get when I run my program is this: reactor:72: 5
This is my code:
local reactorInfo = {
  isActive = false,
  coreTemp = 0.00,
  casingTemp = 0.00,
  energyBuffer = 0,
  fuelAmount = 0,
  maxFuelAmount = 0,
  fuelPercentage = 0.00,
  fuelReactivity = 0,
  wasteAmount = 0.00,
  wastePercentange = 0.00,
  nControlRods = 0,
  controlRods = {
  }
}

local function getReactorInfo()
  reactorInfo.isActive = reactor.getActive()
  reactorInfo.coreTemp = round(reactor.getFuelTemperature(), 2)
  reactorInfo.casingTemp = round(reactor.getCasingTemperature(), 2)
  reactorInfo.energyBuffer = reactor.getEnergyStored()
  reactorInfo.fuelAmount = reactor.getFuelAmount()
  reactorInfo.maxFuelAmount = reactor.getFuelAmount()
  reactorInfo.fuelPercentage = round( (reactorInfo.fuelAmount / reactorInfo.maxFuelAmount) * 100, 2)
  reactorInfo.fuelReactivity = reactor.getFuelReactivity()
  reactorInfo.wasteAmount = reactor.getWasteAmount()
  reactorInfo.wastePercentage = round( (reactorInfo.wasteAmount / reactorInfo.fuelAmount) * 100, 2 )
  reactorInfo.nControlRods = reactor.getNumberOfControlRods()
	if (reactorInfo.nControlRods > 0) then
	  for i=1,reactorInfo.nControlRods do
		reactorInfo.controlRods[i] = reactor.getControlRodLevel(i)
	  end
	end
end

Is there anything wrong with it?

EDIT: I'm using BigReactors.



#218430 Colored text in terminal

Posted by rockymc on 24 May 2015 - 03:19 AM in Ask a Pro

I have a program setup that is just a BigReactors reactor monitor. It prints information about the reactor in any monitor attached to the computer.
However, I'm having a problem: the last written line on the monitor flickers. It is weird, all the other lines are working normally, but then the last one flickers.

Here's my code:

monitor.clear()
  monitor.setTextScale(0.5)
  monitor.setCursorPos(1, 1)
 
  monitor.setTextColor(colors.white)
  monitor.write("Reactor: ")
  if reactor.getActive() then
   monitor.setTextColor(colors.green)
   monitor.write("online")
  else
   monitor.setTextColor(colors.red)
   monitor.write("offline")
  end
  monitor.setTextColor(colors.white)
 
  monitor.setCursorPos(1, 2)
  monitor.write("Core Temperature: ")
  monitor.setTextColor(getTempColor(round(reactor.getFuelTemperature(), 2)))
  monitor.write(round(reactor.getFuelTemperature(), 2).." °C")
  monitor.setTextColor(colors.white)
 
  monitor.setCursorPos(1, 3)
  monitor.write("Casing Temperature: ")
  monitor.setTextColor(getTempColor(round(reactor.getCasingTemperature(), 2)))
  monitor.write(round(reactor.getCasingTemperature(), 2).." °C")
  monitor.setTextColor(colors.white)
 
  monitor.setCursorPos(1, 4)
  monitor.write("Energy Buffer: ".. reactor.getEnergyStored().." RF")
 
  monitor.setCursorPos(1, 5)
  monitor.write("Fuel: ")
  monitor.setTextColor(getColorForFuelAmount())
  monitor.write(string.format("%.2f%%", round((reactor.getFuelAmount() / reactor.getFuelAmountMax()) * 100, 2)))
  monitor.setTextColor(colors.white)
 
  monitor.setCursorPos(1, 6)
  monitor.write("Waste: ")
  monitor.write(string.format("%.2f%%", round((reactor.getWasteAmount() / reactor.getFuelAmount()) * 100, 2)))
  monitor.setTextColor(colors.white)
 
  monitor.setCursorPos(1, 7)
  monitor.write(string.format("Fuel Reactivity: %d%%", reactor.getFuelReactivity()))
 
  monitor.setCursorPos(1, 9)
  monitor.write("Capacitor Energy: ")
  monitor.setTextColor(getColorForCapacitorEnergy())
  monitor.write(capacitor.getEnergyStored().." RF")
 
  monitor.setCursorPos(1, 10)
  monitor.write("")
  monitor.setTextColor(colors.white)

Is there something in it which causes the flickering?



#218404 Colored text in terminal

Posted by rockymc on 23 May 2015 - 10:54 PM in Ask a Pro

View Postflaghacker, on 23 May 2015 - 10:37 PM, said:

Sure:
term.write ("white")
term.setTextColor (colors.red)
term.write ("red")

Ain't no other way? I have a program that controls my BigReactors reactor, and instead of using:
print("REACTOR TEMPERATURE: "..reactorTemperature)

I use:
print(string.format("REACTOR TEMPERATURE: %d", reactorTemperature))

Hm... I think I should add support for color codes, then I substring these codes and set the terminal color.



#218400 Colored text in terminal

Posted by rockymc on 23 May 2015 - 10:26 PM in Ask a Pro

Is it possible to color just a part of this string? Like, "white red", color the red word with the red color?