tulamide's Recent Forum Activity

  • Thank you

  • I'm sorry to have to ask this, but I currently have no possibility to run Construct and need to know, how I would access TimeDelta within Python. Which one is correct?

    a = b * System.TimeDelta()[/code:1rir2uwv]
    [code:1rir2uwv]a = b * System.TimeDelta[/code:1rir2uwv]
    [code:1rir2uwv]a = b * System.GetTimeDelta()[/code:1rir2uwv]
    
    Or is it one not listed here?
  • It's a bit confusing. What exactly are you trying to achieve?

    1) Do you need Python code or Construct events?

    2) When will Sprite.X need to be temporarily saved? Once at start of layout? At several times when certain conditions are met?

    3) How long will it need to be saved? Just before changing Sprite.X until it is changed? Or for a specified amount of time?

    Please give an example (not programming specific)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • No.

    All that the function needs is a position to start at. In the example it is the horizontal center of BadGuy and the vertical top.

    To make this function work independent of BadGuy, just add 2 parameters to the function, the x and y of the starting point. Let's say you have a sprite named "anotherBadGuy". When calling the function, do this:

    -> Function: Add Parameter someDamage

    -> Function: Add Parameter anotherBadGuy.Left + anotherBadGuy.Width / 2

    -> Function: Add Parameter anotherBadGuy.Top

    -> Function: Call function "DMG"

    Now change the function itself to work with the new parameters.

    Change the following:

    -> System: Create object "numbers" on layer 1 at (BadGuy.Left+BadGuy.Width/2-Global('width')/2+Global('temp'), BadGuy.Top)

    into:

    -> System: Create object "numbers" on layer 1 at (Function.param(2) - Global('width') / 2 + Global('temp'), Function.param(3))

    Whenever you want to display damage near an object, just pass an x and y value as parameters 2 and 3 like in the "anotherBadGuy" example above.

  • My pc went to nirwana so I can't use Construct, but from what I saw on the blog, the function expects a string, not a number. Do

    -> Function: Add parameter "12"

    EDIT: And if you intend to use numbers instead of text, inside the function "DMG" just replace every

    Function.param(1)

    with

    str(Function.param(1))

  • Hi, i have been testing the python examples to load videos using python by R0J0hound and these work great. There is a problem however which is if i try to change it to use the app path i get errors.

    This works -

    flash.LoadMovie(0, r'C:\Tooltip.swf')

    These won't -

    flash.LoadMovie(0, r'.\Tooltip.swf')

    flash.LoadMovie(0, r'System.AppPath + Tooltip.swf')

    I tried various other things but nothing works but the fixed path so i am wondering what is the correct way to make it load a file from the same folder as the app instead?

    You can't use variables inside string literals (r'...'). That's the reason for the last one not working. The second but last is not working, because you need to pass an absolute path, but .\Tooltip.swf is a relative path.

    r indicates that the string literal should be used untouched, not interpreting escape sequences, which start with a backslash. When working with variables, you can't add r as a prefix. There are three ways to pass a working path as a variable (although the first two are not recommended):

    1) Replace all backslashes by slashes.

    my_path = 'C:\folder\data.ext'
    my_path.replace("\", "/") # Converts to 'C:/folder/data.ext'
    flash.LoadMovie(0, my_path)[/code:75jpkwxo]
    
    2) Double all backslashes.
    [code:75jpkwxo]my_path = 'C:\folder\data.ext'
    my_path.replace("\", r"\\") # Converts to 'C:\\folder\\data.ext'
    flash.LoadMovie(0, my_path)[/code:75jpkwxo]
    
    3) The usual way to create and maintain working file paths is using the module os.
    [code:75jpkwxo]import os
    my_path = os.path.join(os.getcwd(), "data.ext") # Creates an absolute path adding data.ext to the current working directory
    flash.LoadMovie(0, my_path)[/code:75jpkwxo]
    os.getcwd() is the Python equivalent to System.AppPath, if your cap is stored in C:\Scirra\myProject then os.path.join(os.getcwd(), "data.ext") returns C:\Scirra\myProject\data.ext (well, the string would read "c:\\scirra\\myproject\\data.ext", but that's how Python works with strings and paths)
  • The edit box only knows text. You access its content with 'Get text' (Editbox.Text). But Python does not autoconvert the text to a number. So use the Python-built-in function float(), e.g.:

    Convert.set_hue(float(EditBox.Text))[/code:2v0yez47]
  • I couldn't think of anything easier than calling a function "hsv_to_rgb"

    If you don't want to use Python, you can always do your own conversion events. Converting between color models involves some math, here is one example code (or adapt the one from the shader):

    http://books.google.com/books?id=fGX8yC-4vXUC&pg=PA304#v=onepage&q&f=false

  • That are two different demands.

    1) Hue

    Will never stand alone, it is part of some models that represent RGB in another geometry. You will find 3 models, HSV, HSL, HSI (Hue Saturation [Value, Lightness, Intensity]). In case you need to convert from one of the first two models, Python is the easiest way:

    import colorsys
    my_rgb = colorsys.hsv_to_rgb(0.25, 0.5, 0.4)
    r = my_rgb[0] * 255
    g = my_rgb[1] * 255
    b = my_rgb[2] * 255[/code:3prbcqlu]
    
    [i]A more useful implementation[/i]
    
    1. Put the following script as a subevent of 'Start of layout':
    [code:3prbcqlu]import colorsys
    
    class FromHSV(object):
        def __init__(self):
            self.__h = 0
            self.__s = 0
            self.__v = 0
    
        def set_hue(self, hue):
            self.__h = hue
    
        def set_saturation(self, saturation):
            self.__s = saturation
    
        def set_value(self, value):
            self.__v = value
    
        def get_red(self):
            return colorsys.hsv_to_rgb(self.__h, self.__s, self.__v)[0] * 255
    
        def get_green(self):
            return colorsys.hsv_to_rgb(self.__h, self.__s, self.__v)[1] * 255
    
        def get_blue(self):
            return colorsys.hsv_to_rgb(self.__h, self.__s, self.__v)[2] * 255
    
    Convert = FromHSV()[/code:3prbcqlu]
    
    Then, as soon as you have the HSV values, use any of these to fill the class:
    [code:3prbcqlu]Convert.set_hue(yourhuehere)
    Convert.set_saturation(yoursathere)
    Conert.set_value(yourvalhere)[/code:3prbcqlu]
    
    And finally, whereever you need the rgb, use the functions get_red, get_green or get_blue. In the rgb expression it would be:
    [code:3prbcqlu]RGB(Python("Convert.get_red()"), Python("Convert.get_green()"), Python("Convert.get_blue()"))[/code:3prbcqlu]
    
    2) From any range of numbers
    I'm not sure what you mean. Basically, red, green and blue are expressed as values in the range [0, 255]. If you have values in another range, just normalize them and then map them to [0, 255]. For example, v in range [0, 1000] would become v / 1000 * 255, v in range [3, 20] would become (v - 3) / 17 * 255, etc.
  • No, no, use Door.Y-(100*timedelta).

    I may misunderstand this, but if you mean the parentheses I should say that they are not needed in the example. Construct follows the mathematical rules of order for arithmetic operations. Multiplication and division has higher priority than addition and substraction.

    Door.Y - 100 * TimeDelta

    Door.Y - TimeDelta * 100

    Door.Y - (100 * TimeDelta)

    All three do exactly the same. First multiplying 100 with TimeDelta (or TimeDelta with 100, which doesn't make a difference in multiplication), then substracting the result from Door.Y.

    I tired it and I really don't like it. I tired Door.Y-0.25*timedelta and it move super slow, like 0.25 every second. I had to do like Door.Y-100*timedelta. I'm not use to using big numbers. I really know nothing about timedelta because I never used it.

    Like PixelRebirth said, don't think in fractions but in the resulting period. If you aim for your game to run at 60 fps and add 1 pixel per frame, then the effective pixel rate is 60 * 1 = 60 pixels per second. And value * TimeDelta simply means "that much of value per second" (and Construct cares about how much of that needs to be used per frame). So, when your game would run constantly with 60 fps, then

    +Always
    -> Set x to x + 1[/code:3tmazibc]
    and
    [code:3tmazibc]+ Always
    -> Set x to x + 60 * TimeDelta[/code:3tmazibc]
    do the same. But if the framerate changes, then the second event makes sure, the speed is still constant 60 pixel per second.
    
    TimeDelta is a number that expresses the time passed between the current and the last tick. On a system where there is constant 60 fps, TimeDelta will be 1/60 (or 0.016p) on every tick. Now multiply 60 with 0.016p. Yeah, it's 1, just as wanted and expected.
    
    Of course, TimeDelta serves as an indicator for all changes and hickups in the framerate, not only a constant change. And that's what makes it so flexible and guarantees a constant line of whatever you need (movement, speed, rotation, color fade, etc.) over time, by using higher or lower portions per frame to compensate.
  • Just for the record (and for the curious):

    You can also always create your own decimal places. But you need pv's or globals for the interim results to avoid rounding errors.

    number n = 23.452612

    you want three decimal places

    1) int/round/ceil/floor(n*1000); store the result in a variable v. [v = 23452 or 23453, depending on your rounding choice]

    2) result = v / 1000 [result = 23.452 or 23.453, depending on your rounding choice]

  • If there is only an "is down" condition for the controller, then refine your first appoach. Add a global "isPaused" and combine the "Start is down" condition with "Trigger once"

    + Start is down

    + Trigger once

    -> Set isPaused to 1 - global('isPaused')

    This will set isPaused to 1 on every first press of Start, and to 0 on every second. Then add

    + isPaused equal to 1

    -> Set time scale to 0

    + else

    -> Set time scale to 1

    I don't know, if controller buttons are still detected if time scale = 0 (I don't have a controller), but apart from that the events above [s:mjylicny]will[/s:mjylicny] should work.

tulamide's avatar

tulamide

Member since 11 Sep, 2009

Twitter
tulamide has 3 followers

Trophy Case

  • 15-Year Club
  • Coach One of your tutorials has over 1,000 readers
  • Email Verified

Progress

17/44
How to earn trophies