Page 1 of 1

Help: Dragon Language Translator - buttons and stuff

Posted: Thu May 31, 2012 9:54 pm
by Yolo
Okay, so this is what I want to create:

I am trying to make a recreational application (hard to consider it a game) and what it does is to use this giant dictionary of english to dragon language words.

You type in a sentence, and then you press the button "Translate". The game tries to convert as many english words available for translation into dragon language and prints it right below. The words that cannot be translated are left as the original words.

Right now, I have the part where you can type in anything (only letters + numbers), and I am just trying to get the button to at least print something so I will know that I can move on to the translation part of the script. By the way, I am pretty mediocre or even lower about pure lua coding and love lua. I've only learned my knowledge on lua from a game called ROBLOX.

So my help here is pretty much to make the button work and for another question: is there a possible way where I can have a function from another script be usable in the main.lua? You will see my DragonLanguageTranslator.lua in my file. (Not done translating all the possible words, but it is still usable)

I see that I have some errors in this script, so I was wondering if anyone can help me. I am pretty sure that you will try to see what I mean from the coding. I have some notes for you in the coding.

And thank you so very much if you are willing to help me.

Re: Help: Dragon Language Translator - buttons and stuff

Posted: Thu May 31, 2012 10:29 pm
by Roland_Yonaba
Welcome around.

You're trying to compare a string and boolean. Lua assumes this is always false.
See this and this for more info.
Change this.

Code: Select all

local on = false
--instead of local on="false"
Plus, you're drawing the confirmation message "Hello" out of the screen.
Move its y position to a less lower value.

Re: Help: Dragon Language Translator - buttons and stuff

Posted: Thu May 31, 2012 11:06 pm
by Yolo
*Smacks myself in the face for absent-minding-ly adding the quotes for the word false*

Wow, I didn't even catch myself do that. How much should I make the y value lower? And you mean the " love.graphics.print("hello",10,400) " part?

Re: Help: Dragon Language Translator - buttons and stuff

Posted: Thu May 31, 2012 11:10 pm
by Yolo
Nevermind. I fixed it. Thank you.

And another thing:

Is it possible for me to use that DragonLanguageTranslator.lua function in the main.lua, or do I have to copy and paste the whole function in that script in put it in the main.lua?

Re: Help: Dragon Language Translator - buttons and stuff

Posted: Thu May 31, 2012 11:25 pm
by Santos
Yolo wrote:Is it possible for me to use that DragonLanguageTranslator.lua function in the main.lua, or do I have to copy and paste the whole function in that script in put it in the main.lua?
Sure is! Assuming main.lua and DragonLanguageTranslator.lua are in the same folder, putting...

Code: Select all

require "DragonLanguageTranslator"
...at the top of main.lua (or anywhere before you use what's in DragonLanguageTranslator.lua) should work.

(Note that there is no .lua at the end of the file name)

Re: Help: Dragon Language Translator - buttons and stuff

Posted: Fri Jun 01, 2012 12:27 am
by Yolo
Santos wrote:
Yolo wrote:Is it possible for me to use that DragonLanguageTranslator.lua function in the main.lua, or do I have to copy and paste the whole function in that script in put it in the main.lua?
Sure is! Assuming main.lua and DragonLanguageTranslator.lua are in the same folder, putting...

Code: Select all

require "DragonLanguageTranslator"
...at the top of main.lua (or anywhere before you use what's in DragonLanguageTranslator.lua) should work.

(Note that there is no .lua at the end of the file name)
Great!

So if I state a function that is inside the DragonLanguageTranslator in my main.lua, it will work?

Re: Help: Dragon Language Translator - buttons and stuff

Posted: Fri Jun 01, 2012 12:49 am
by Santos
Yolo wrote:So if I state a function that is inside the DragonLanguageTranslator in my main.lua, it will work?
Sure will! ^^

To clarify, there is no ".lua" at the end of a file name when using "require", but there is in the filesystem. So name your file DragonLanguageTranslator.lua, and require it in main.lua with require "DragonLanguageTranslator"

Re: Help: Dragon Language Translator - buttons and stuff

Posted: Fri Jun 01, 2012 10:01 am
by Roland_Yonaba
Yolo wrote: Is it possible for me to use that DragonLanguageTranslator.lua function in the main.lua, or do I have to copy and paste the whole function in that script in put it in the main.lua?
Yolo wrote: So if I state a function that is inside the DragonLanguageTranslator in my main.lua, it will work?
Indeed, it will.
As I like providing links, learn more about require here.
Anytime you use require, it loads the designed file, adding every variables defined inside in the global environment.
So that they can be accessible everywhere, even inside the file where you make the call.
But, use it with caution, and pay attention to scoping. I don't like messing with globals, as it's commonly mentionned as a bad programming behaviour...