Help: Dragon Language Translator - buttons and stuff

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Yolo
Prole
Posts: 4
Joined: Thu May 31, 2012 9:30 pm

Help: Dragon Language Translator - buttons and stuff

Post 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.
Attachments
DragonLanuageTranslatorAppHelp.love
(4.94 KiB) Downloaded 236 times
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Help: Dragon Language Translator - buttons and stuff

Post 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.
Yolo
Prole
Posts: 4
Joined: Thu May 31, 2012 9:30 pm

Re: Help: Dragon Language Translator - buttons and stuff

Post 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?
Yolo
Prole
Posts: 4
Joined: Thu May 31, 2012 9:30 pm

Re: Help: Dragon Language Translator - buttons and stuff

Post 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?
Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

Re: Help: Dragon Language Translator - buttons and stuff

Post 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)
Yolo
Prole
Posts: 4
Joined: Thu May 31, 2012 9:30 pm

Re: Help: Dragon Language Translator - buttons and stuff

Post 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?
Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

Re: Help: Dragon Language Translator - buttons and stuff

Post 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"
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Help: Dragon Language Translator - buttons and stuff

Post 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...
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests