Jump to content




HEEEEELP

computer lua help

10 replies to this topic

#1 joshgreat

  • Members
  • 33 posts

Posted 12 July 2017 - 02:59 PM

ok. so im making an OS and im making a multi user account system, sadly this comes up with an error. if someone can find the error and tell me whats wrong that would be dandy. Thanks

LINK

https://pastebin.com/HH67n4YQ

p.s this is only a portion of the code

#2 KingofGamesYami

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

Posted 12 July 2017 - 03:25 PM

That should not throw an error. Are you sure this is the right file and line number?

It won't work properly in any case, since fs.exists takes one parameter not two.

#3 joshgreat

  • Members
  • 33 posts

Posted 12 July 2017 - 03:48 PM

It has a problem adding strings as when i make it print the variable after 2 have been added it is wrong and only shows the 1st string

#4 KingofGamesYami

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

Posted 12 July 2017 - 03:54 PM

"Adding strings" is called concatenation. The operator for this in Lua is two periods. Example:
print( "Hello " .. "World!" )


#5 joshgreat

  • Members
  • 33 posts

Posted 12 July 2017 - 04:17 PM

I have a problem with adding variables as well as it does the same

#6 KingofGamesYami

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

Posted 12 July 2017 - 04:43 PM

That sentance makes me want to stop helping you.

#7 joshgreat

  • Members
  • 33 posts

Posted 12 July 2017 - 05:51 PM

sorry, its the same solution isnt it?

#8 diamondpumpkin

  • Members
  • 59 posts
  • LocationPlaces, Ukraine

Posted 12 July 2017 - 06:15 PM

View Postjoshgreat, on 12 July 2017 - 05:51 PM, said:

sorry, its the same solution isnt it?

Sort of... Adding two variables is dependent on the variable type. So a string variable would work as a string just without quotes.

ex = "Hello"
ex1 = "world"
print(ex .. " " .. ex1)

Outputs:
Hello world

However, if the variable is a number use it as you would a number

print(5 + 5)
Outputs:
10

num = 5
num1 = 6

print(num + num1)
Outputs:
11

Mixing the two will not work. It will throw an error. If you want to a print a number in a string, easy.

n = 1
print("Hello, you are " .. tostring(n) .. " person.")
Outputs:
Hello, you are 1 person.

Or you could just change the original variable to a string:
tostring(n)

If you want to do the opposite, say in a math equation, you'll need to use tonumber().

n = "5"
tonumber(n)
if n == 5 then
  print(5)
end

This code is unoptimized because it was done quickly, however it's still a decent example.

#9 Dog

  • Members
  • 1,177 posts
  • LocationEarth orbit

Posted 12 July 2017 - 06:58 PM

One thing you missed, diamondpumpkin, is that you need to capture the output of tonumber() and tostring() to a variable. They don't change a variable/value, they output a new value.

local n = 1
local nString = tostring(n)


#10 joshgreat

  • Members
  • 33 posts

Posted 12 July 2017 - 07:33 PM

Thanks guys il edit my code :-D

#11 Bomb Bloke

    Hobbyist Coder

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

Posted 13 July 2017 - 12:09 AM

View Postdiamondpumpkin, on 12 July 2017 - 06:15 PM, said:

Mixing the two will not work. It will throw an error.

Actually, Lua will quite happily concatenate strings with numbers, or add string representations of numbers together:

print("2" + "2") --> 4

print("2" + 2) --> 4

print(2 .. 2) --> 22

print("2" .. 2) --> 22

That said, you can't pass a string into something like a "for" loop or a numeric comparison without doing something to convert its type first.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users