Тёмный

Tutorial 3: Variables in Lua 

Gamefromscratch
Подписаться 252 тыс.
Просмотров 10 тыс.
50% 1

Опубликовано:

 

16 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 70   
@gamefromscratch
@gamefromscratch 6 лет назад
Lua/Love Links: www.gamefromscratch.com/page/GameDev-For-Complete-Beginners-Tutorial-Series.aspx
@DustyMusician
@DustyMusician 7 лет назад
"You can use all the data types the light touches." "What about that shadowy place?" "That is userdata. You must never go there."
@JaclynFox
@JaclynFox 8 лет назад
42^2 is 1764
@TopazCentuallas
@TopazCentuallas 8 лет назад
I love the way you explain things and It would be really useful for me and a lot of other people if you in future could make a tutorial series about Modern C++. I just can't grasp it on my head and there isn't that good tutorials out there and the way you explained LUA is perfect. Thanks anyway!
@gamefromscratch
@gamefromscratch 8 лет назад
+Greedy TopAz I have considered it. The big problem with C++ is complexity. For example, when it comes to datatypes, for number types in C++ there are: char, int, double, float, long, signed/unsigned versions, bool (yes... its a number type...) When do you use each? Largely it's a matter of what platform you are working on, which compiler you are using, etc... were on some platforms, certain int types will operate 10x slower than others, while on different platforms, this is completely different. How big is each data type? Well... this again depends on which platform and which compiler you are using. Hell, the order the number is even stored in (endian-ness) is platform dependent. With this obscene amount of variety, and inconsistent implementations, its very easy to be wrong or misleading. It is something I have considered writing for a very long time, as I know many people are using on particular RU-vid source and its absolute garbage.
@TopazCentuallas
@TopazCentuallas 8 лет назад
Which is exactly why it is so hard to grasp it on my head. There are just too many different documentation based on different compiler or language version that it is almost impossible to know what the correct and efficient way of doing something is. But when it comes to speed, there is no other choice except C++. C# and Java afaik has never been used in any AAA games that is released.
@rafaelbezerra9178
@rafaelbezerra9178 8 лет назад
+Greedy TopAz But for beggining, C++ is not a good choice...
@TopazCentuallas
@TopazCentuallas 8 лет назад
Honestly, the only thing I can't grasp is the pointers, memory allocation and garbage collection. I got use to the syntax.
@TopazCentuallas
@TopazCentuallas 8 лет назад
The heap and stack.
@MereddynYT
@MereddynYT 8 лет назад
Nice Series. BTW You forgot modulo as an operator
@Quiloos39
@Quiloos39 8 лет назад
Please make tutorial about how to use library's for lua (luarocks etc..)
@swagluke2370
@swagluke2370 6 лет назад
#include //Where the system function is located. int main() //The main entry point of the application { system("lua53 "); // Using the console command to run lua code. system("pause"); // So it don't immediately exit out. return 0; // telling the console everything ran fine and we can quit. } in C++ so you don't need to keep doing lua53 Batch Version: @echo off lua53
@zainsagar
@zainsagar 5 лет назад
Hello mike . How do u learn so how I a good manager. Keep up bro. Thanks for all tutorials u make.
@Cerbyo
@Cerbyo 5 лет назад
local string = "heyo" print (heyo) doesn't work when doing it in the command prompt....that ramcha or whatever u called it where u open lua in command prompt and test stuff out directly there. If u get rid of the local it works there though. Little things like this cause great frustration for me when learning. I think you should indicate that the code we do in our interpreter won't work the same as writing it in the command prompt or at least in this case. Does this hold true for anything else or is this one of those exception things?
@rho2101
@rho2101 5 лет назад
Hey, dude, I'm a complete beginner so I might be wrong, but I think that code should be as follow" local string = "heyo" print (string) You used the value in the "print" command, instead of using the variable. Edit: I actually understand the problem you are facing, now, as I tried to emulate it on my command prompt and had problems as well. Using local when setting a variable always return a nil. I'm also curious to why that happens.
@QuotePilgrim
@QuotePilgrim Год назад
Alright, hopefully both of you figured it out by now, but for future reference in case anyone else stumbles upon this: From what I could gather, when you assign a local variable at the start of the script, it gets scoped to the whole script, so print(string) is able to print the value of your variable. Within the interactive prompt, however, there is no script to scope the variable to, so it ends up being scoped _to that single line of code._ As a result, when you type print(string), there is no variable named "string" in the current local scope, which means the print function is looking for the variable "string" in the global scope and, since no such variable was ever assigned, it prints nothing. Try typing "local string = "hello" print(string)" all in one line in interactive mode, and you'll see that it works. Also, you can reference a local variable assigned within a function's scope in interactive mode the same you would in a script. So if you define a function: function sayHello() local myString = "hello" print(myString) end And then call the function with sayHello(), it will work as expected.
@Cerbyo
@Cerbyo 5 лет назад
I wanted to write a quick equivalency test comparing 2 variables as seen below. I would expect the first "YES" value to never display. But what happens is that its always YES so long as I'm checking its equal to a value no greater than 2. I don't get it, as this seems to indicate that local dog = 3 is actually saying dog = 0, 1 , 2, 3; and cat = 0, 1 , 2. So if I'm checking if cat and dog == 3,4,5,6+ its no, but if cat and dog ==2, 1 ,0 its yes. I'm definitely not understanding something here. local dog = 3 local cat = 2 if cat and dog == 2 then print("YES both numbers are equal to 2") else print("NO they are not both equal to 2") end
@rho2101
@rho2101 5 лет назад
If I'm running local dog = 2 local cat = 3 if dog and cat == 2 then print ("YES") else print ("NO") end My program always says NO. If I run something like local dog = 2 local cat = 3 print ("cat and dog == 3") It always says true. Same if I use print (cat and dog) to which it answers 3. Pretty weird.
@ronpaynter7054
@ronpaynter7054 6 лет назад
I haven't done any serious coding in a long time so I'm just looking into different things and ended up here. From what I'm seeing Lua looks like it might be fun to work with. It sounds like userdata is something similar to passing parameters from say dll's. I'll have to look into it later on once I'm more familiar with the language. I'm surprised that it has the option to assign threads. Lua seems like it might be a bit more powerful than I was initially thinking. I have to say that the section on boolean numbers was a bit confusing and if I didn't already understand the subject I would probably be totally confused by the whole thing.
@gadenlich
@gadenlich 9 месяцев назад
K.the operation is v. Aher . Antiugo .
@gadenlich
@gadenlich 9 месяцев назад
K.the operation is v. Aher . Antiugo .
@gadenlich
@gadenlich 9 месяцев назад
K.the operation is v. Aher . Antiugo .
@gadenlich
@gadenlich 9 месяцев назад
K.the operation is v. Aher . Antiugo .
@gadenlich
@gadenlich 9 месяцев назад
K.the operation is v. Aher . Antiugo .
@ccdrobin6962
@ccdrobin6962 6 лет назад
does this still apply in 2018? Cause I really wanna learn this. Im completley new to any computer language
@gamefromscratch
@gamefromscratch 6 лет назад
+CCD Robin yep, should still be 99% accurate. If anything changes in Love it's generally documented in comments.
@ccdrobin6962
@ccdrobin6962 6 лет назад
Thank you :) I know you have done a bunch of videos for lua, if you don' tmind making the same kind of lua videos but if you could go more in depth with what each variable ect does I would really appreciate that(I have no experience with programming at all). Maybe give some examples aswell like "okay so this code could be used in my "game" that im making and what it does is that when I press on the health potion it should drink it/use it. Thank you and will be continuing to watch the rest of the lua vids tomorrow, cause I need to learn this for Dota2 modding :)
@AlexLoranger
@AlexLoranger 6 лет назад
so used to != lol thanks Lua guess you need to be different somehow
@K5-Tech
@K5-Tech 8 лет назад
is it possible with lua to use the operator like += instead of x = x + b?
@gamefromscratch
@gamefromscratch 8 лет назад
Short answer, no. Medium answer, sadly no. Long answer, still no, with a but. That but is source level patch ( lua-users.org/wiki/LuaPowerPatches ) adding them. I do believe you can emulate them as well, but another advanced too.
@K5-Tech
@K5-Tech 8 лет назад
ah thats to bad :/
@DarkerCry
@DarkerCry 8 лет назад
+Gamefromscratch That's a bit disappointing. Is there a reason why it hasn't been added in yet? I really can't think of many languages that don't have them.
@gamefromscratch
@gamefromscratch 8 лет назад
+Lonely Goblin There are a few (GDScript in Godot for one). I think it's mostly a matter of language simplicity. It's easily enough added to the core langauge. At the end of the day it's just syntactical sugar anyways, so while I miss them, they dont really take much away and I can see how some could make the argument they make for harder to read code. I can also see how people can argue they make more readable code too... ;)
@DarkerCry
@DarkerCry 8 лет назад
Gamefromscratch That's true, I'm just lazy and x++ is quicker than x = x +1 :P
@garageman2236
@garageman2236 4 года назад
I hate that there's none of this int MyInt = 7; it's just local MyInt = 7
@chimashw6070
@chimashw6070 8 лет назад
local calc = 42 * 2 ~= 42^2 -- eheheheheh
@gamefromscratch
@gamefromscratch 8 лет назад
+Chimas HW oops...
@humbleBT-v
@humbleBT-v 8 лет назад
+Gamefromscratch I love the way you engage your viewers, by using a very relative enthusiastic tone in your voice . To me those make for the best instructors , because a boring teacher voice is no fun right.lol On a serious note though , do you honestly feel that once a individual develops those core principles to coding , it forever becomes a piece of cake for them ?
@gamefromscratch
@gamefromscratch 8 лет назад
Piece of cake might be a bit strong, but yes. I would say learning your second language takes a fraction of the effort of learning your first. I'm not talking syntax here... I mean, once you actually understand programming using a single language, learning different programming languages is a lot easier. These days after working in so many different languages, I can generally pick up and be productive in a new programming language within a few hours to days. Of course, learning the fine nuances takes much longer. There are some exceptions. For example, learning a functional language like F#, Haskel or LISP is going to require a bit of a loop in the way your brain works and are going to take a bit longer to come to terms with. They will still be easier to pick up with a good solid foundation in another programming language. Of course you can go your entire life without every learning one of these languages. Also this is becoming less of a point too, as aspects of functional programming languages are being adopted in traditional languages ( such as lambdas and closures ). Glad you enjoyed the tutorials. Cheers.
@humbleBT-v
@humbleBT-v 8 лет назад
Gamefromscratch Thank You !
@garageman2236
@garageman2236 4 года назад
Who thought ~= > !=
@mrteadie
@mrteadie 4 года назад
Coding your own game? It's easier than you think..........
@UrsaFrank
@UrsaFrank 8 лет назад
And, Or, Not... you forgot Xor
@gamefromscratch
@gamefromscratch 8 лет назад
+DonpatchXD Xor did I? ;)
Далее
Tutorial 4: Functions in Lua -- Gamedev for Beginners
14:49
Falling in LÖVE with Lua
1:12:27
Просмотров 71 тыс.
Why I Dont Recommend Starting with C++
27:06
Просмотров 55 тыс.
Learn Lua in an Hour
55:18
Просмотров 325 тыс.
Lua Tutorial
57:25
Просмотров 963 тыс.
Vectors & Dot Product • Math for Game Devs [Part 1]
3:16:28
Clean Code - Uncle Bob / Lesson 1
1:48:42
Просмотров 1,9 млн