[LUA] Ep. 7 - Basic Functions

preview_player
Показать описание
In this video we take a look at the basic "must-know" features of functions, What they do and how they are useful. If you have any questions feel free to leave a comment and I will get back to you. If you liked it or learnt anything then feel free to leave a like!

=========USEFUL STUFF========
Рекомендации по теме
Комментарии
Автор

Rest in peace Code Blue you helped me alot

LorTinooo
Автор

Wow, I've never been able to understand code in a way you're presenting it to me, all your tutorials it feels like I've gained more knowledge than I've ever had about Lua, which is very little. Thanks man! How 2 Earn Subz ^^

strajee
Автор

Old video but this was a great function tutorial

tist
Автор

I love these videos you explain it so well I'm learning so easily

themagicshow
Автор

I run a racecar with a data logger that is at least partly programmed with Lua scripting. I'm getting only minimal help from the manufacturer, so I'm trying to find some help, and came across your video. It looks like this video is hitting very close to what my issue is that I'm trying to accomplish. I'll make it as brief as I can, but if you aren't familiar with the Auto Sports Labs MK3 data logger, it might take a little more information than I know how to state.

I have 3 shift lights in my racecar. I've been able to get each of them to work off of reading RPM only with some help from someone else. Here is the script that has them working, based on RPM only:

function onTick()
rpm=getTimerRpm(0) --read RPM
--activate LEDs

if rpm > 1600 then setGpio(2, 1) else setGpio(2, 0) end
if rpm > 1700 then setGpio(1, 1) else setGpio(1, 0) end
if rpm > 1800 then setGpio(0, 1) else setGpio(0, 0) end
end

Essentially, I don't understand how the first 3 lines work. I believe that I do understand how the remainder works, and feel that I can modify it to get what I ultimately want, if I can understand the first 3 lines.

Here is what I'm trying to accomplish:

I would like to have each of the shift lights to work off of "RPM" and "speed". To help you understand the purpose, think about it like this. My car accelerates much more quickly at lower speeds. Thus, I need the shift light to come on earlier at low speeds, to keep me from running up against the rev limiter of the engine. Reverse is true for higher speeds. Both RPM and speed are column headings of the data when I download the data to a spreadsheet format.

Here is one example of the script that I've tried, with negative results. I was trying to test the system in the shop with the car stationary, so instead of referencing speed, which would require the car be moving, I am referencing "tpsvolts", which references the throttle position sensor in volts (tps volts or "tpsvolts"):

function onTick()
rpm=getTimerRpm(0) --read RPM
tpsvolts=gettpsvolts (0) --read tpsvolts
--activate LEDs

if (rpm > 1600 and tpsvolts > 1) or (rpm > 1900 and tpsvolts > 1.6) or (rpm > 2100 and tpsvolts > 2.2) then setGpio(2, 1) else setGpio(2, 0) end
if rpm > 1700 then setGpio(1, 1) else setGpio(1, 0) end
if rpm > 1800 then setGpio(0, 1) else setGpio(0, 0) end
end

In this test, I set the rpm values low, for simple testing, and I only changed the script by adding the "tpsvolts=gettpsvolts (0) --read tpsvolts" line and modifying the gpio2 line from the original script. gpio2 is general input output control, which controls an electrical internal switch to turn the lights on and off. gpio 1 and 2 are the remaining 2 shift lights of the 3.

confidentiallyMe
Автор

I've had a reallyl hard time with return. its making more sense now tho in ur example. because u want sum and its a calculation within the function u have to always print the value of sum. with return u can make sum the automatic thing that gets pumped out, so then u can just print the function itself and assign the function to a variable and print that itself and get the value of sum

Cerbyo
Автор

What I want to know: how to use strings, how to create basic commands, how to function stuff..

ChrisTaylor-xoup
Автор

5:59 just gonna bookmark this cuz wtf 😭

Jeremy-lhlg
Автор

If the function end when u type return sum why we need to type end? at the end of the function

shoamtalker
Автор

watching these to learn roblox scripting because if i just search "roblox tutorials" they just tell me to copy and paste their script and sont explain anything on how it works and stuff

getvictored
Автор

I just watch other tutorial but here's the function is red and the other was blue and i do it fine but it's still red and nothing works help me please

Kigumi-
Автор

coming from a C# background. I find one thing very disturbing about the way LUA does functions.

ex1...
function anyName(name)
print(name)
end;

name = "Tristan"
anyName();
io.read();

works the same as

function anyName()
print(name)
end;

name = "Tristan"
anyName();
io.read();

I understand that name is a global variable, but just thought I would share that it bothers me :)
not dissing the language or anything. I am new to LUA and all, but this just boggles the mind. maybe the next video will sum it up for me...
really like the videos though.
Learning a lot...

DWTA
Автор

what is wrong here? it wont open


function anyName(a, b)

sum = a + b
return = sum


end

test = anyName(10, 20)



print(test)







io.read()

Drewbien