User Tag List

Results 1 to 3 of 3

Thread: Noob on board... how to create random objects

  1. #1
    No Products Registered

    Join Date
    Dec 2008
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Noob on board... how to create random objects

    I need to learn how to randomly generate objects on screen. More specifically, I would like to randomly generate letters 'a-z' on the screen. (My long term goal is make a basic typing practice program where random letters fall/scroll across the screen and the user keys the letters that are presented.)

    Could someone point me to the right tutorial/thread? I've looked for a good while, and due to my noob-like knowledge level, I have yet to find what I am looking for.

    Any help will be greatly appreciated!


  2. #2
    Forum Moderator Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export Module
    DavidN's Avatar
    Join Date
    Jun 2006
    Location
    Boston, MA, USA
    Posts
    4,044
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Noob on board... how to create random objects

    Hi rhodestown, and welcome to the community!

    There are a number of different ways to do most anything in MMF, so experimenting around with your own approaches is recommended as well as following anything that I say. However, the easiest method that's coming to my mind for what you've described there is creating a String object (it doesn't matter what its initial contents are), assign it a Bouncing Ball movement going down the way, then:

    On the event that triggers the falling of a letter:
    Create "String" at (0, -64)
    Set X position of String to random(Frame Width) [This event will place the String object at a random position along the playfield]

    ... and after that it gets a bit more involved than I ancitipated at first. I've put an example up in the File Archive at http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=119689 .

    The idea is now to get the String to display a random letter each time it's created. To do that, I used a second String object with the entire alphabet in it, and then set the alterable string of the first String object to this, which might appear a bit... daunting:

    Mid$(string$( "String 2" ), Random(Len(string$( "String 2" ))-1), 1)

    Mid$ is an expression that can take smaller strings (in this case, individual letters) out of strings. It takes three pieces of information - the large string to look in (the contents of the string containing the alphabet, in this case), and then the number of the character to start from and the length of the string to produce (1 in this case, as we only want one letter).

    The middle argument is the most complex - we want to start from a random point through the 26-letter string. We use Random(n) to do this, which is an expression that returns a random number from 0 to (n-1). Our 'n' in this case is the length (Len()) of the alphabet string, minus one as string characters are counted beginning from zero. So in our alphabet string, A would be at character 0 and Z would be at character 25.

    In the example file, that event's added to the list that I started earlier, and I've also put in an action to change the colour of the text each time a new String is created.

    I might have started too quickly depending on how familiar you are with concepts like this to start off with - however, bear in mind that this is just one way of doing it and there are many others that may seem simpler!

  3. #3
    No Products Registered

    Join Date
    Dec 2008
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Noob on board... how to create random objects

    Thank you. I've been away from programing for a good while (8 yrs or so), so even something as easy as a string is rather daunting.

    The example is a good start for me. It makes sense once I see how it's dropped into MMF.

    (EDIT: The following link was for a search on Mid$. It helped me to fully grasp your string statement. Posting for others if the need arises http://www.w3schools.com/vbscript/func_mid.asp )

    Thanks man. -Dan

Similar Threads

  1. Random Chunk Generator using "Create New Objects"?
    By darkmanx_429 in forum Multimedia Fusion 2 - Technical Support
    Replies: 8
    Last Post: 7th August 2013, 12:42 PM
  2. Create random objects
    By Captain_Harris in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 7th August 2012, 06:28 PM
  3. Advanced Game Board Object - deleting active objects
    By Wackyjackie in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 5th May 2012, 07:03 AM
  4. Rasndomly place objects on the board on start
    By krestalex1 in forum Multimedia Fusion 2 - Technical Support
    Replies: 9
    Last Post: 22nd May 2008, 07:45 PM
  5. Create a random object from set
    By invicticide in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 29th December 2007, 07:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •