Rectangles that randomly appear

Creating Games? Developing something for fun?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8516
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Rectangles that randomly appear

Post by dunbarx » Fri Dec 10, 2021 11:48 pm

else
answer "Incorrect guess, try again"
end if
Just so.
currentChoice = [1, 2, 3, 4, 5]

print(random(.)choices(currentChoice))
The reason I asked the questions I did is because of the above. You are generally not using the correct syntax, which is why I thought you were very new to LC. You seem to be using syntax from another language (Python?).

An array variable is populated differently than your statement above, though I see the logic of it. The print line just is not valid in several ways. The good news is that you appear to have experience, and all you need is to learn just a little of the LC language and structure. That is what I meant when I said you need to play and practice.

Read up on the "random" function. Also on the "any" keyword. Also an "array" in LC is a special and very compact variable type. It is populated and read as Klaus mentioned. It needs practice to master.

So keep at this project. But read and play as well.

craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8516
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Rectangles that randomly appear

Post by dunbarx » Fri Dec 10, 2021 11:58 pm

Check out the user guide, page 118.

Arrays.

Craig

thrwawy
Posts: 8
Joined: Thu Dec 09, 2021 6:06 pm

Re: Rectangles that randomly appear

Post by thrwawy » Sat Dec 11, 2021 12:19 am

I'm just continuing on with a website for it instead, however, I appreciate both you and Klaus' efforts, LiveCode just isn't for me :lol:

Klaus
Posts: 12990
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Rectangles that randomly appear

Post by Klaus » Sat Dec 11, 2021 12:24 am

thrwawy wrote:
Sat Dec 11, 2021 12:19 am
I'm just continuing on with a website for it instead, however, I appreciate both you and Klaus' efforts,...
You're welcome!
thrwawy wrote:
Sat Dec 11, 2021 12:19 am
... LiveCode just isn't for me :lol:
Too verbose? :D

thrwawy
Posts: 8
Joined: Thu Dec 09, 2021 6:06 pm

Re: Rectangles that randomly appear

Post by thrwawy » Sat Dec 11, 2021 12:27 am

Too verbose? :D
Haha yeah, makes it much more difficult to remember the syntax

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8516
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Rectangles that randomly appear

Post by dunbarx » Sat Dec 11, 2021 6:32 pm

Haha yeah, makes it much more difficult to remember the syntax
I have heard this so many times before, since 1987 in fact. Those who come from other languages find the english-like structure of LC off-putting.

But think about it. I know it is different, but wouldn't the IDEAL programming language be idiomatic english? Something like:

Code: Select all

Um, sort that field by looking at the second character in each line

or, more to the point of this thread

select a random image from the list based on what the user selects in an ask didalog
Do you see what you are leaving on the table by not taking the time to change your thinking?

craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6631
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Rectangles that randomly appear

Post by jacque » Sat Dec 11, 2021 7:06 pm

What you want to do is much easier than you think. First, populate a list of numbers in a variable:

Code: Select all

put "1,2,3,4,5" into tNums
Now choose a random number from the list and use concatenation to create the name of the image to show :

Code: Select all

put any item of tNums into tNum
put "rect" & tNum into tImageName
show image tImageName
Edit: if you want to avoid random selections that repeat numbers already used, we can show you how to do that.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8516
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Rectangles that randomly appear

Post by dunbarx » Sat Dec 11, 2021 9:27 pm

Jacque
The OP wanted to show several images. The selection of a random number also has to delete that choice from the possibles.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6631
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Rectangles that randomly appear

Post by jacque » Sat Dec 11, 2021 10:01 pm

dunbarx wrote:
Sat Dec 11, 2021 9:27 pm
Jacque
The OP wanted to show several images. The selection of a random number also has to delete that choice from the possibles.
That's what I meant with my edit. And it was my understanding that only one image was to be shown at a time; the user guesses a number and the pre-chosen image is compared to that to determine if the guess was correct. I didn't include any tracking in my example. The simplest way would be to set a script local holding the pre-chosen number. But that can come later.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8516
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Rectangles that randomly appear

Post by dunbarx » Sat Dec 11, 2021 10:41 pm

Hmmm. You could be right. The first sentence of the OP's first post seemed to say a few.

@thrwawy If you are still with us, what do you intend?

And just so you know, a reasonably competent LiveCoder could build a fully functioning app in half an hour,. Artwork, bells and whistles are not included, which would likely take longer than that, as usual. Try that in any other environment.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 7541
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Rectangles that randomly appear

Post by richmond62 » Wed Jul 27, 2022 4:03 pm

Reviving an old thread:
LiveCode just isn't for me
I wonder why: the OP does not seem to explain that adequately.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9207
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Rectangles that randomly appear

Post by FourthWorld » Wed Jul 27, 2022 8:12 pm

Seems pretty clear the OP had moved on long ago. Locking this thread to prevent further random necromancy distraction.
Necromancy.jpg
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Locked

Return to “Games”