Random text in Corona - coronasdk

Totally new with Corona and asking for some support.
Would like to create a simple first software with Corona. My idea is to have a button and when you press the button you see different words on the screen. The idea is that they roll randomly and then stops on one word. For example 8 different words and one is chosen and a few seconds and shown on the screen.
For an expert I guess this is imple but for a rookie it´s not that easy.

Use a array of words to store the words
local words = {foo, bar, hi, no, yes, mom, dad}
Then use math.random to select a word.
local wordIwant = math.random(#words) -- # operador gets the length of a list
So if math.random returns 3 for example, wordIwant will be "hi"
:)
Now how you do your special effect and other pretty stuff, is up to you, but I recommend using the enterFrame listener for that.

Related

Maxima for Android (and PC as well): How to reuse the result of a calculation

Let's say I enter this symbolic calculation in Maxima for Android:
integrate(sin(x)*x,x)
The answer is beautifully displayed thanks to MathJack (it is sin(x)-x*cos(x)). Ok, thanks. But now I would like to tap in that answer and have it in the command line, ready to be modified (for instance I may want to multiply it by some number and then use it in another calculation).
What I want is something similar to pressing the "ANS" key in some calculators, where the last result the machine yielded can be used as new input.
In Xcas Pad this is easy and straightforward (just touch on the result, that's all). How to do that in Maxima for Android? (The answer for the PC version of Maxima is also appreciated).
Remark: Copy-paste does not work in Android, because the answers are Latex-formatted or something similar.
You can tap the answer formula displayed with Mathjax in the main area. The maxima expression will be entered in the bottom command area, as you wanted.
Actually, the commands displayed in the main area are also tap-able. You can tap one of them and it is entered in the bottom command area.

Lua script for iOS getColors within range?

I am trying to capture the pixel color of a specific letter in a font within an iOS app. I'd then use that color in an if/then statement to determine the next action of my script. I'm finding no easy way to determine if the color/colors I'm finding are the right ones. Here's my current process: I start recording my inputs and continuously click around the letter. I end up with something like touchdown(123,456). I change that to alert(getColor(123,456)) and run, which produces a popup that tells me the color such as 3094841 (not sure why the colors are in numeric format, but they are). I do this for each touchdown line that is captured. The problem is, I don't know an easy way to determine which color is the small letter I'm trying to tap.
Is there a lua function that will capture and display a range of colors between 2 points? If there were, I could see the commonality of all of the colors within the 2 points and make at least an educated guess as to which is the color in the font. Or even more useful - is there a tool I can use to type in the color I'm getting back and have it display the corresponding color, so I can compare them. That'd be the easiest. Hope this makes sense. Any help would be awesome. In case it matters, I'm using Autotouch 8 on an iPhone 5.
TIA
I use this function often in my games.
I find the easiest way to get a color you want to execute every single time is to take a snap of the screen you're checking and then use the helper on getColor(x, y)
And you can use this to alert your color.
local color = getColor(x, y)
alert(color)
-- You can also use:
log(color)--this one keeps it in your log in case you can write it down immediately.
To use this in an if/then statement
function = namedfunction()
local color = getColor(x, y)
if color == YOURCOLOR then
else
end
end
namedfunction();
Note that I have the iPhone 5 iOS 8.3 and I have the most recent AutoTouch from Cydia. If you don't have the helper when you're scripting it might be worth it to check if Cydia offers a capatable version.
Edit: I am running version 3.5.3-8 of Autotouch.

How to continuously Increment & Decrement with (+1) & (-1) in iOS calculator without the Button "="

First sorry for my poor English.
I am creating a basic iOS calculator for iPhone 6, since I am a beginner for iPhone development.
Everything is working fine, addition, subtraction etc.
Now I want to make this calculator app for black jack card counting.
But my question is:
Q) Is it possible to continuously calculate add +1 to the value without the "=" button? That is I want to continuously add +1 when I press (Low +1) button and subtract -1 when I press (High -1) button?
Please give me some suggestion. And Sorry again for my poor English.
Well, one suggestion would be to provide a up and down button (or increment and decrement or whatever else you might call them) which simply added or subtracted one from the current display value.
Depending on how your code is structured, this could be as simple as something like:
case INCR_BTN:
setDisplay (getDisplay() + 1);
break;
case DECR_BTN:
setDisplay (getDisplay() - 1);
break;
(in C, but similar enough to ObjC that it'll help out).
But keep in mind I don't think many of the casinos are going to let you sit at their Blackjack tables messing about with your iPhone :-) The best card counters are the ones that do it in their head but, even then, if you seem to be winning too much, they'll start cutting the shoe earlier to remove any advantage counting may give you.

Shifting elements in match3 kind of game

I am a beginner at ActionScript3, and for my learning purpose, I am trying to build a match3 kind of game. I am making is a clone of bejeweled kind of game. but instead of swapping, I have to delete those elements and shift the upper elements down and add new elements above those shifted elements.
I am able to delete matched elements and after matching I'm removing those elements but I am stuck with the shifting code. I am not able to shift those elements down.
I believe that you should take a look at Richard Lord's Tetris source code as your game may be somehow similar in mechanics to Tetris. Tetris shifts down rows when you get lucky.
Richard Lord is one of the Flash Gurus and his way of doing things may seem pretty advanced for a starter like you. Take a look over the source code and see if it fits you. What I can tell is that this is the proper way to make a game but maybe it's not the best point to start for a novice like you that is in urgent need.
http://www.richardlord.net/blog/actionscript-3-tetris-source-code
I would approach it like this in 2 parts.
Loop through your array of board positions starting from the bottom row and check for an empty unoccupied slot, if you find one do another loop through the row above till you find a piece on the same column. If you find a piece on the row above apply a tween to move it down to the empty slot and continue your loop.
Once you have looped through all rows, and animated all the tweens you need to loop through again to find all the gaps that need gems dropped into them. Create new elements at those positions and then move them up by (element height * row), apply another tween to animate them back to their starting position.

ActionScript Timeline Control

I'm dynamically loading a file that will indicate when to show certain words at certain frames. However, I'm having trouble with the concept of timeline control from ActionScript (I'm building everything programmatically in Flash Builder). Let's say my tuples has frame and word:
5, "duck"
13, "cow"
22, "pig"
There is a sprite associated with each. What I would like to do is something like the following:
for (frame in timeline) { //should iterate from frame 0-22 (last frame in list)
if (frame in list) {
list[frame].alpha = 0;
}
}
I already know that my display of sprites works and whatnot, I'm just confused on how to play through the timeline in this kind of way, or if it's possible to dynamically do this.
EDIT: Related, can I control how fast the timeline plays?
EDIT: To give a more thorough explanation, I'm looking to visualize word appearances over time in a text. So "duck" may appear as the 5th word in a corpus, "cow" as the 13th word, etc. My list contains tuples of word positions (unique) and the word that appears at that position. I have a small selection of words that I'm interested in from the corpus, so not every position is represented. I would like to be able to have a SWF movies that essentially starts at the beginning of the corpus, go through my word list in order of appearance in the corpus, and then display the word (and have it fade out). So, if there's a word at position 5 and 10, then should appear in much more rapid succession than if there's a word at position 15, and the next one doesn't appear until 50. Basically, I would like to keep that temporal component.
I'm having a little trouble understanding exactly what you're asking about, but in general for controlling the timeline use the commands play() stop() gotoAndPlay() gotoAndStop()
Beyond that I'm gonna need you to explain more clearly what exactly you are trying to do.
ADDITION: From your edits it sounds like you simply want to trigger an animation when the user clicks a button or something. So make the animation in Flash and then use the commands I listed to play it.
ADDITION2: If however you definitely want to do this in code then that has nothing to do with the timeline; program the fading in and out using a tweening library like http://www.greensock.com/tweenlite/

Resources