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

CraftOS 1.71 with string.gsub

Started by biggest yikes, 05 March 2015 - 09:01 PM
biggest yikes #1
Posted 05 March 2015 - 10:01 PM
I was messing around with CC a while ago, and I noticed that the following code

local version = os.version()
print(version:gsub("Craft", "Cyan"))
Actually prints out "CyanOS 1.71" instead of the proper result, "CyanOS 1.7" in CC 1.73.

Yet the actual version number is CraftOS 1.7, even with the Lua console..

Can someone explain why this is? I'm not sure if it's a glitch in 1.73 or something, but I find it strange.

EDIT: Turns out it was just because I returned the first and second output instead of just the first. Oops ._.
Edited on 05 March 2015 - 09:11 PM
MKlegoman357 #2
Posted 05 March 2015 - 10:04 PM
string.gsub returns the changed string and a number of how many matches were replaced. That's where that '1' comes from: it replaces only one match.
biggest yikes #3
Posted 05 March 2015 - 10:04 PM
string.gsub returns the changed string and a number of how many matches were replaced. That's where that '1' comes from: it replaces only one match.
Oh, I see, my bad :P/>
Edited on 05 March 2015 - 09:05 PM