This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
AlexG2490's profile picture

Modify a program to increase the length of a printed variable

Started by AlexG2490, 29 March 2015 - 03:31 PM
AlexG2490 #1
Posted 29 March 2015 - 05:31 PM
Hello all! I'm a real newbie when it comes to computercraft, but my question is (I think) a pretty general LUA question. I've deployed Dragonlord's RF Control Center in my base successfully. Here are links to the release thread and the pastebin of the code:

Thread: http://www.computerc...607#entry178607
Pastebin: http://pastebin.com/TfeHE7Wy

Basically, the program monitors your capacitors and reactors, lists all of your power banks, and the amount of energy stored in each one. I put this on a computer, and it connects and displays all the information that it's supposed to. However, the max energy that it will attribute to any one capacitor is 25000000 RF.

My capacitor bank has a capacity of 294,175,000,000, so the number of significant digits on display isn't enough to be meaningful.

I have some very limited experience with code (VB, HTML, CSS) so I tried to figure this out myself, but I don't seem to be able to, though I would like to learn.

First, the number 25000000 seemed like an odd place to cut off - I would think if I maxed out the variable it would be 99999999 - so I searched the code for that number to see if a maximum was defined anywhere. No dice.

The string the program prints on screen is "Max Energy Storage: 25000000 RF" so I searched for the string "Max Energy Storage". There I found this:

print(padRight("Max Energy Storage: "..totalCapacity.." RF"))

totalCapacity is a dimensioned variable up above in the code, but I don't understand the dots before and after the variable in the print string. Do they define anything?

I'm sure this is a really easy question and I'm just not getting it because I'm unfamiliar with LUA syntax. If anyone can help a newbie learn something, it would be very much appreciated.

Thank you in advance!
KingofGamesYami #2
Posted 29 March 2015 - 09:02 PM
.. is simply a concat operator. They simply join two strings together, eg:


print( "Hello" .. " " .. "World" )
--#is the same as
print( "Hello World" )
--#it's commonly used to show variables
local name = read()
print( name .. " says Hello World" )
Bomb Bloke #3
Posted 29 March 2015 - 11:56 PM
First, the number 25000000 seemed like an odd place to cut off - I would think if I maxed out the variable it would be 99999999 - so I searched the code for that number to see if a maximum was defined anywhere. No dice.

Remember that computers deal with values in base 2, not base 10. A "maxed out variable" will therefore typically be nearly equal to a power of two.

Not that 25mill is anywhere near a power of two, mind you, but neither's 100mill, for that matter. What 25mill is supposed to represent is the maximum amount of energy your combined capacitors can store. I gather each bank can hold something like 5mill RF, so this suggests you have… five cells? And that you'd need nearly sixty thousand cells to achieve ~294bill worth of storage?
AlexG2490 #4
Posted 31 March 2015 - 05:53 AM
.. is simply a concat operator. They simply join two strings together

Oh, OK, I think I get it. So the practical example you showed allows you a shortcut, in order to combine variables and strings together without having to convert the variable to a string just for display purposes. Am I understanding that right?

…What 25mill is supposed to represent is the maximum amount of energy your combined capacitors can store. I gather each bank can hold something like 5mill RF, so this suggests you have… five cells? And that you'd need nearly sixty thousand cells to achieve ~294bill worth of storage?

Hehe. I know it's a ludicrous amount of power. The Vibrant Capacitor Bank is a multiblock structure, and mine fills a football field-sized area. I was using World Edit in creative mode, my selection area was larger than I thought it was, and one server-crashing worldedit later I had more power than the entire energy output of the sun for a decade or something like that. Now the fun question is how long it's going to take to drain the damn thing (hence the monitoring). So it's big, but not nearly as big as 60,000 cells. It's closer to 10,000. Barely ridiculous at all! ;)/>

Something you said got me thinking, though. Upon examining a block by itself, I discovered that each block of the multiblock structure structure can actually contain 25,000,000 RF - the exact point at which the program stops registering. That makes me think the program is working as expected but somehow is only monitoring one block of the multiblock structure, in which case it is doing what it's supposed to and I just have to figure out how to tell it that the target is a multiblock. I believe the mod author has a tutorial video so I am going back to re-watch a second time and see if I might have missed part of the setup or done something wrong.

Thanks for the jumping off point; I feel like I'm on the right track now.