Advertisement
XxSpiritDuoxX

Variables

Feb 9th, 2022
835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.95 KB | None | 0 0
  1. --[[
  2. Here we are, Anyways, Welcome to the beginning of the scripting basics guide thingy
  3.  
  4. Anyways, lets start
  5.  
  6.  
  7. ---------------
  8.  
  9. Roblox Studio uses the coding language: Roblox Lua
  10.  
  11. It is the roblox language used by all games and its a modified version of lua
  12.  
  13. But anyways, here is the general stuff and dictionary you want to know first before
  14. diving into any kind of coding:
  15.  
  16. =====| Math Sign |=====
  17. Very important btw
  18.  
  19. + = Addition
  20. - = Subtraction
  21. * = Multiplication
  22. / = Division
  23. % = Modulus (added this since this is not percentage as you may think)
  24.  
  25. =====| Variables |=====
  26.  
  27. Variables are the very core of scripting, They hold a value and thats what they do
  28.  
  29. This is a variable, and below here, you can see that the variable named "Example", stores the value
  30. "nil", nil doesnt mean anything, its basically what is the value given if it doesnt exist or is nothing
  31. ]]
  32.  
  33. Example = nil
  34.  
  35. --[[
  36.  
  37. Variables can store many more variables, including themselves
  38.  
  39. Think of variables like a small box you can put things in
  40.  
  41. Here is a small list of stuff
  42. a variable can store
  43.  
  44. ]]
  45.  
  46. Integer = 1
  47. --This is an integer variable, it holds a number
  48. Float = 4.2145
  49. --Floats are the same as the one above, except the numbers have multiple decimals
  50. --Integers turn into Floats when you add a decimal to them
  51. String = "text"
  52. --Strings are variables that hold text
  53. Boolean = true
  54. --Booleans are variables that hold true or false values
  55. vector3 = Vector3.new(1,1,1)
  56. --Vectore3 values are values that hold a Vector3, They are commonly used for xyz Positions
  57. color3 = Color3.fromRGB(0,0,255)
  58. --Color3 values are just variables that hold a Color3 in RGB format
  59. Table = {1,2,3}
  60. --Table values hold a table of values, a bit complicated and you shouldnt worry about
  61. --trying to understand what this does until much later
  62.  
  63. --[[
  64. Here are examples of variables being used
  65. ]]
  66.  
  67. Coins = 5000
  68. DamageMultiplier = 1.45
  69. DialougeText = "Hello!"
  70.  
  71. --[[
  72. Along with Variables, you can also use something called print()
  73. ]]
  74.  
  75. print()
  76.  
  77. --[[
  78. Print basically prints a value to Outpute (which can be viewed in VIEW >> Output: https://gyazo.com/3c2ad715475c7aceff188a4e861a47ff)
  79.  
  80. Print can display any variable and combinations of them, The ">" displayed under a print says what
  81. will be printed to Output
  82. ]]
  83.  
  84. print("Here is some text")
  85. -->Here is some text
  86.  
  87. print(24 + 20)
  88. -->44
  89.  
  90. print("First Line")
  91. print("Second Line")
  92. -->First Line
  93. -->Second Line
  94.  
  95. --Here is something interesting about prints: You can print variables directly
  96. --Here is an example
  97.  
  98. textToPrint = "Hello!"
  99.  
  100. print(textToPrint)
  101. -->Hello!
  102.  
  103. --[[
  104. now lets get into something slightly more complex
  105.  
  106. For variables, Variables can also store other variables, And Variables can be added or 'fused' together
  107.  
  108. Example:
  109. ]]
  110.  
  111. integer1 = 51
  112. integer2 = 23
  113.  
  114. print(integer1 + integer2)
  115. -->74
  116.  
  117. int1 = 50
  118. int2 = 40
  119.  
  120. int3 = int1 + int2 --This sets the value of int3 as the additive of int1 and int2
  121.  
  122. print(int3)
  123. -->90
  124.  
  125. --[[
  126. And finally, about Variables, They can be edited and overwritten
  127.  
  128. Just like a box of items, You can put more stuff in, or take everything out of the box and
  129. put something new in
  130.  
  131. (except that box can only have one type of thing)
  132.  
  133. Examples:
  134. ]]
  135.  
  136.  
  137. integer = 50
  138. integer = integer + 12 --This is the exact same as 50 + 12, as "integer" has the value 50
  139. --^^^note that you can shorten this with +=,-=,*=,/=, These are the same thing
  140. --example:
  141.  
  142. value1 = 124
  143. value1 += 50 --Takes value1 and adds 50, then sets value1's value as the new value
  144.  
  145. --Back to original topic
  146.  
  147. variable = 125
  148. variable = 275
  149. --This sets the value of "variable" to 275, you can also overwrite it with an entirely new type of value
  150.  
  151. something = 524
  152. something = "newValue"
  153. --This turns "something" into a string value, a new variable isnt created, just overwritten
  154. --Using the variable named "something" just uses the new value instead
  155.  
  156. --[[
  157. This should be the basics of variables i think
  158. ]]
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement