User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11

Thread: Random Bug?

  1. #1
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Aug 2006
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Random Bug?

    I seem to have noticed a few bugs but i am not sure. The first is the random values i am getting back seem to be sequenced rather than real random. Maybe Lua has a random that is no good or something but if i close and re-load the app i get the same values as last time.

    Also if i have 2 functions in a embedded script where in one function i set a active objects angle etc using random, then in another function get it's angle it will always have 0 for the angle result at the start of the frame. This seems like a bug but could be due to the random values in sequence.

    The code is simply -

    Code:
    function set()
    mmf.Object.SetAngle(1,math.random(0,359),false)
    mmf.Object.SetX(1,352+math.random(-100,100))
    mmf.Object.Update(1) 
    end
    
    function get()
    angle = mmf.Object.GetAngle(1)
    x = mmf.Object.GetX (1)
    return angle,x;
    end
    I export the active to ID1, run embedded script, call the get and set functions then get back the values to counters. The MMFI, bind state and libs are just set in the properties.

    As a workaround to the angle getting 0 you can call the functions twice but it works however it still has the sequenced values problem and the workaround shouldn't be needed also.

    Is the default random just bad? or is this a bug or code error?

  2. #2
    Clicker Multimedia Fusion 2
    Retriever2's Avatar
    Join Date
    Jun 2006
    Location
    United States
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Random Bug?

    Did you call math.randomseed at the start of your application?

    Lua's math.random simply falls through to ANSI C's rand, which requires you to set a seed once or you'll just repeat your sequence each run.

  3. #3
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Aug 2006
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Random Bug?

    I am not sure how to be honest, i tried math.randomseed(100) above the functions which still has the same thing happen, also in a function called before them at the start of frame but i get the same thing again. Basically every time i close the app and start it again it's the same values.

    Do you have a quick mfa example or code of a working version if possible?

  4. #4
    Clicker Multimedia Fusion 2
    Retriever2's Avatar
    Join Date
    Jun 2006
    Location
    United States
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Random Bug?

    randomseed needs to be different each run (the seed is what defines the sequence returned by the number generator.) Typically the seed is set to a time value which is going to be different each run.

    math.randomseed(os.time())

  5. #5
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Aug 2006
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Random Bug?

    Thanks, using the time as the seed seems to fix the sequence problem.

    I still notice one problem though and that is when the app runs the first value for the angle always seems similar, for the X value however it seems fine. With the angle if you start it and it's something like 59 then on restarts the first number can sometimes be 59 again or just very close and something like 60, so it's like it gets the time rather than the random value.

    I just place the math.randomseed(os.time()) above the set function because i noticed that does the same as just giving it a function.

    So yeah it's basically fixed however the first value is not sorted and oddly only for the angle value. The workaround is to call the set function twice which will make it a lot better.

    By the way with the angle range am i correct in using 0-359? or should that be 0-360 etc instead, maybe that could be the reason.

  6. #6
    Clicker Multimedia Fusion 2
    Retriever2's Avatar
    Join Date
    Jun 2006
    Location
    United States
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Random Bug?

    Are you trying to set and get the value in the same frame? The change may not be visible until the following frame. I know this is true for setting object position.

    I think the angle is just taken modulo 360 so any value is valid.

  7. #7
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Aug 2006
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Random Bug?

    Yeah i do it together with set called first. Basically my events are like -

    Start of frame:
    Export active with ID1

    Start of frame:
    Run embedded script
    Call set
    Call get

    Button clicked:
    Call set
    Call get

    And a always event setting counters with the named floating variables "angle" etc to test the results. After testing it works fine with xy positions etc but the angle reacts differently in that it has a timer style result where it's the same value when re-loading the app for a while and takes 1 click press before the random starts to work correctly.

    Maybe there could be a new Delayed Call action? So it's like -

    Delayed Call "set" (1 Millisecond Delay)

    By the sounds of things this would fix the problem and also be nicer for the event structure than needing sub events with timer conditions or double calls etc as a workaround. I can think of a lot of other useful things that could be done with this also.

    Or is that possible in the Lua code without the need for a new action?

  8. #8
    Clicker Multimedia Fusion 2
    Retriever2's Avatar
    Join Date
    Jun 2006
    Location
    United States
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Random Bug?

    I think you'll need to provide me an example to fully explain what you're encountering.

    XLua is fully synchronous with MMF so I can't do an arbitrary call after some period of time. But then again, neither can MMF, since your "xx delay" events are really in terms of some discrete number of frame ticks.

    You should be able to emulate that with a little extra work. You could define a new function that wraps DoCall, say DoDeferredCall(func, delay, ...), and in that function, instead of actually calling func with its arguments, you would add func and its arguments as a record to some global table, along with its delay value.

    In MMF, you would have an always event that calls some DeferredCallHandler function in Lua. The purpose of that function is to scan through the global table of deferred calls and decrement the delay value of all the functions in it. When the delay value of a function reaches 0, it is executed by passing the original function and arguments to DoCall.

    Actually I described the opposite procedure of what you wanted, but you could flip it around and still implement it in Lua code. It might be a little clumsy.

  9. #9
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Aug 2006
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Random Bug?

    I think you'll need to provide me an example to fully explain what you're encountering.
    Here is a mfa, i made a note inside to explain it. Basically when you run it the randomize never works for angle until you do a second call (press the randomize button). It seems to be working fine for the position however.

  10. #10
    Clicker Multimedia Fusion 2
    Retriever2's Avatar
    Join Date
    Jun 2006
    Location
    United States
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Random Bug?

    It seems to be a known issue.

    The suggested work-around is to call math.random once or twice after setting the seed to discard the first value. The problem may be endemic to the underlying rand() function itself, which is already known to be pretty weak.

Page 1 of 2 1 2 LastLast

Similar Threads

  1. Random Active Spawn in Random Location in Frame
    By Top_of_the_Temple in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 20th October 2016, 03:33 AM
  2. Random object spawning random y set x
    By Armiferamortalis in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 23rd December 2013, 11:47 AM
  3. Make Random Pool not-so-random?
    By UltraHammer in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 4th April 2013, 02:53 PM
  4. BUG: Random is not random in Flash mode
    By oldkliker in forum SWF/Flash Export Module Version 2.0
    Replies: 1
    Last Post: 11th October 2011, 08:56 PM
  5. Random Speed + Ypos at random times
    By Keehan in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 14th May 2011, 05:25 PM

Posting Permissions

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