Does anybody know lua code?

hopscotch
poll
helpwithcode

#1

Does anybody know LUA coding?

If so, reply and use the poll.

If not, do the same.

  • Yes, I do know lua. :smile:

  • No, sorry. :pensive:

0voters

Because I need help with something I'm making for

Hopscotch.


#2

I don't know what it is but I'd love it if you told me!


#3

Are you planning to transfer something you made in Lua into a Hopscotch project? Like @JumpyJose said, it would be great if you could tell us :smiley:


#4

@JumpyJose Lua is a type of coding. Like html, javascript, python, and the one with the bad name.

@t1_hopscotch This might sound derpy, but I plan on making a lua script for my open url block topic. We are thinking about having it share other projects only, like c.getopscotch.com/blank. If someone said yes i know, here's what i'd tell them:


    Great! So this is the Lua I typed in:

    function myFunction()

    donut = {"gorwsgt","xcw2nfyuz"}
    print ("c.gethopscotch.com/")
    print (donut)

    end

So where did I mess up?

yeah i know it stinks. Sorry!


no seriously sorry :pensive: :cold_sweat: :grin:


#5

Also I'm pretty sure @BuildASnowman knows Lua.


#6

@H4x0r
So: A few pointers on your code.
You are defining your function right, but you are forgetting to call it. When you define a function (It's like an ability in hopscotch) you have to call it, so after your code put:

myFunction()

You also are defining a table called donut which you never reference, but that doesn't mess up your code, just is some extra work for the compiler.

When you do

print(dount)

It will print some weird thing like:

table: 0x34t5

Which is the memory adres of the table. If you want to print the things in the table, use a for loop and cycle through each of the elements like so:

for k,v in pairs(donut) do
 print(v)
end

And then the main thing you are working on, your first print:

print ("c.gethopscotch.com/")

Will just print out the text

c.gethopscotch.com/

Lua doesn't actually have a built in ur/website api, which means you can't use lua for what you are doing. You can, however, use python. A tutorial for urls with python would be a bit too long for here, so what I will do is edit your open url post with a script for it.


#7

So should I put:

math.randomseed(os(time))
function myFunction()
donut = {"gorwsgt","xcw2nfyuz"}
print ("c.gethopscotch.com/p/")
for k,v in pairs(donut) do
print(v)
end

By the way when I try to call that global table an error occurs :confused: @BuildASnowman Please reply.


#8

What I'm saying is that you can't actually use lua for this, because you can't connect to urls using lua.


#9

Just wondering, what does Lua specialize in? As in, HTML is text such as websites, JavaScript is usually for design, etc.


#10

@BuildASnowman I'm not trying to connect to a website, I'm just trying to make it display the text c.gethopscotch.com/p/gorwsgt, or c.gethospcotch.com/p/xcw2nfyuz

:neutral_face:


#11

Oh! In that case just use this code:

print("c.gethopscotch.com/p/gorwsgt")

You don't need functions or anything like that


#12

No, I mean it could say that, but it could possibly also be c.gethopscotch.com/p/xcw2nfyuz.


#13

Sorry for the late response!
So, what you are saying is you want it to sometimes say c.gethopscotch.com/p/xcw2nfyuz and sometimes say c.gethopscotch.com/p/gorwsgt?


#14

Yes! And no worries on the late response :blush:


#15

The best way is using "tables", which is the name for lists in lua.
The way you define a table in lua is this:

list = {"item1,"item2"}

And then when you want to reference an item in that table:

print(list[2])

Would print out the second element in the list.
So, first we define a table of the things we want it to say:

urls={"c.gethopscotch.com/p/gorwsgt","c.gethopscotch.com/p/xcw2nfyuz"}

Then all we have to do is get a random item in this table.
Well, to do this we need something called math.random. It allows us to generate random numbers.

print(math.random(1,10)) would print a random number between one and ten. But what will our range be for this?
There is an operator in lua which is "#". It just means length, so #urls would be how many items are in the table.
So, this code:

print(math.random(1,#urls))

Would print a random number between one and the amount of items in the table urls.
Then, we just have to actually put it in a reference:

print(urls[math.random(1,#urls)])

And that will give us a random item in the list and print it out!
So our final code for that:

urls={"c.gethopscotch.com/p/gorwsgt","c.gethopscotch.com/p/xcw2nfyuz"}
print(urls[math.random(1,#urls)])

#16

Thanks @BuildASnowman!! Do I need anything before
urls={"c.gethopscotch.com/p/gorwsgt","c.gethopscotch.com/p/xcw2nfyuz"}
print(urls[math.random(1,#urls)])
?


#17

I'm learning LUA so I can mod Unitale! :D

@BuildASnowman, I need to install LUA. Did you use the .gz file?


#18

Installing Lua is harder than it seems xD. Windows, mac, or something else?


#19

Windows!

I saw two files that both install it; LuaDist and the .gz of the current version. What do I do now :stuck_out_tongue_winking_eye:


#20

You downloaded the binary of it, and compiling a binary in windows is gonna be very difficult (Believe me: 6 years of programming experience and I gave up on it after 7 hours)
I would say your best bet is to use LuaRocks. Here is a link to download:
https://github.com/keplerproject/luarocks/wiki/Download

And here is a link to installation instructions for windows:
https://github.com/keplerproject/luarocks/wiki/Installation-instructions-for-Windows

If you have any questions I'll try my best to help out, although the journey ahead of you depends a lot on luck, patience, and deciphering weird, vague messages (That's a good metaphor for life, too xD)