tulamide's Forum Posts

  • How do you get such a parameter from construct please ? I've searched in the event sheet, but i cannot interact with the effects parameters with it. Is there a way to calculate something in the events or so and send it to the shader ? Or interact with its declared parameters in the event sheet ?

    When I was talking about the world size, I didn't think of something interactive. You know the size of your world/layout, so you could just enter it in the panel. At least that's what I was thinking of.

    During runtime, you would do it this way. Let's say your effect is called "myshader", and one of its parameters is called "World Width" (the display name is the one we need, not the variable name). You apply "myshader" to a sprite with the name "mysprite".

    To set the "World Width" (in pseudo code):

    + Some Condition (e.g. Always)
    -> mysprite: myshader: Set World Width to LayoutWidth[/code:2xe85af2]
    Explanation: You access the shader's parameter with the wizard. After a doubleclick on the object with the shader, you will see a seperate tab for every effect applied to that object. (LayoutWidth is a system expression, in the wizard you find it under 'system', it is called "Get layout width") 
    
    You can also access the parameters of an effect that is applied to a layer. You find the appropriate action of the system object under 'Layer', it is called "Set layer effect param".
    
    There are no getters for effect parameters, you can only set them.
    
    Here is an example of an interaction with the parameters of an effect during runtime.
    [url=http://www.scirra.com/forum/viewtopic.php?f=29&t=5703][EFFECT] Disk[/url]
  • okey now i want to cut myself...

    in your cap, you have 11 frames, and i have 11 frames. in your all frames are correctly displayed coresponding to values. in my, max value frame is like only displayed when Current is higher then Total. the only diffrence is that your cap doesnt have the auto regeneration and doesnt uses decimal values.

    and yes i know i am stubborn but i still havent learned why my method doesnt work when basing on logic it should work.

    Without seeing your cap I can't exactly tell where the problem is. Here is another cap, this time not editable, but the shield regenerates slowly over time and mean meteoroids hit the ship occasionally, substracting from the shield's current value. And all of this with crooked floating numbers, like 678.542 for total or 29.943 for the regeneration value.

    Compare this cap to yours and find the differences, then you will learn why your method doesn't work.

    Download: shipstatus2.cap

  • About the variables from construct : the problem is that i cannot get values relative to the origin of the world. This would be cool to create effects such as colorShift for vegetation, to alterate wind effects, motion or so... and it only adds 1 instruction per shader. Well, maybe this will be added later.

    I see what you mean. Yes, that would be great (and having a timer value also).

    In the meantime, given your effect isn't too instruction heavy, you can get by with the following:

    Add parameters for the current position of the left/top-edge of the display relative to the world. If you prefer to store them as pixel values, that's fine. You can use an always event to update the parameters, or any other method that comes to mind.

    Now the calculation part. There are the variables pixelWidth and pixelHeight.

    1/pixelWidth gives you the current width of the display in pixel, 1/pixelHeight gives you the height of the display in pixel.

    You now have everything you need. For example: dLeft = 320, dTop= 112, dWidth = 1024, dHeight = 768

    You may also add parameters for the width and height of the world.

    And if you have pixel values but need relatives, just multiply horizontals by pixelWidth and verticals by pixelHeight. But make sure, the values are relative to the display, first.

  • I never used the avi object to date, but there is an action 'set repeat', you can set that to 'repeat' or 'no repeat'. I think that's for looping it?

    (v0.99.96)

  • The error message was thrown out, because you forgot the semicolon after sampler. But there were two more issues. You defined parameters for Construct, but didn't define them for the effect. You defined a float4 front but tried to access it as frontTex.

    Here is the corrected code:

    // World recolor
    // Valerien
    // PS 2.0
    // Overlaps an object's color depending on its position in the screen
    
    //#PARAM float redAdd 0.1 : RedShift : Adds red to the object.
    float redAdd;
    
    //#PARAM float greenAdd 0.1 : GreenShift : Adds green to the object.
    float greenAdd;
    
    //#PARAM float blueAdd 0.1 : BlueShift : Adds blue to the object.
    float blueAdd;
    
    //special values extracted from construct
    texture ForegroundTexture;
    // texture BackgroundTexture;
    int boxLeft;
    
    //sampler
    sampler2D foreground = sampler_state
    {
    Texture = (ForegroundTexture);
        MinFilter = Point;
        MagFilter = Point;
        MipFilter = Point;
    };
    
    //ColorShift function
    float4 EffectProcess( float2 Tex : TEXCOORD0 ) : COLOR0
    {
    float4 front = tex2D(foreground, Tex.xy);
    float3 colorShifter;
    
    colorShifter.r = redAdd;
    colorShifter.g = greenAdd;
    colorShifter.b = blueAdd;
    
    boxLeft.x *= 0.1;
    //sin and cos functions are used for
    front.rgb *= ((sin(boxLeft.x) - 2*cos(boxLeft.x)) * colorShifter.rgb)/colorShifter.rgb;
    
    return front;
    }
    
    //technique
    technique ConstructEffect
    {
        pass p0
        {
            VertexShader = null;
            PixelShader = compile ps_2_0 EffectProcess();
        }
    }[/code:3ft8mo3u]
    
    [b]EDIT[/b]
    
    

    Also, is there a way to get the position of the object passed through the shader ? And to get a time value from construct please ?

    I guess you already had a look at this page?

    The only "time value" you get is frameCounter, I'm afraid. Yes, it is not much...

    For positions you have

    boxLeft

    boxTop

    hotspotX

    hotspotY

    pixelWidth

    pixelHeight

    all expressed as a number from 0 to 1, relative to the display.

  • I know it and you know it, newt, but irbis doesn't. In fact, that's why he asked for help. I still think omitting one of the key probs is not helping, but confusing more.

    Anyway, I've made a cap with a nice 11-frame status display and editboxes to play around with different values for 'total' and 'current' while running the app. You will see how simple and yet versatile the formula is.

    Download: shipstatus.cap

  • What ever.

    Still say it's a better way. He just needs to get the value of the variable before he even thinks about setting the frame.

    Then there's the lerp method. You can use 1-10, 1-11, 5-20, and change the modifier to n*0.1.

    And if your terribly worried about returning a zero, all you have to do is change the always condition to a comparison making sure its greater than 0.

    I'm not concerned about lerp, but that we are not talking about one variable, but two. The 'health' value, as you called it, is not a fixed percentage. It is related to another value and both change during gameplay. health = 500 means 100% only if the second value is 500. If it is 800 then health = 500 means 62.5%. And that's not covered by your proposal.

  • Nice one, good work!

    And good luck for all those hot effects we can expect from you from now on

  • Actually, it's a bit more.

    numbers are rounded down to the next integer:

    int(3.2) = 3

    int(4) = 4

    int(5.892) = 5

    strings will be searched for numeric values at the beginning of the string, and the resulting number then rounded down to the next integer:

    int("20") = 20

    int("43.342") = 43

    int("51abcdefg") = 51

    int("51.56abcdefg") = 51

    ...

    and ... int("blah blah") = 0

    Btw, is there a difference between floor(3.2654) and int(3.2654) ?

    I can't really see one, because floor works exactly the same than int (edit: forgot a word) even on strings...

    Lets look at this in a more simplified way.

    If your max shield hp is 1000, and you have 10 different states, you can use that as a percentage.

    >always

    ->sprite set frame to int(shields('health')/100)

    Note:

    Frame 0 is not possible, but the system will use the closest to it frame 1.

    http://dl.dropbox.com/u/666516/framepercent.cap

    And while your looking at the system expressions take a look at lerp.

    int(lerp(1,10, Sprite.Value('hp')/1000))

    This is confusing more than helping. Please have a look at my long post about it. There are two variables that are related to each other and influence each other. Also, my expression never reaches frame 0, I think it is a better way to make sure you don't get unwanted values instead of hoping that Construct will catch the error.

  • What does the range 0 to 100 mean here? (What units are being used here?)

    What value in this range corresponds to the sound file being played at its original volume?

    Also, how do you access this particular variable using syntax? (XAudio2.??)

    Thanks.

    It's a percentage value. 100% should match 0 dB and 0% should match -inf dB. Original volume always is 0 dB, so 100% = original volume.

    Sadly there's only a setter for music volume, no getter. You have to create a pv or global and store/change the value there, then set the music volume to that pv/global.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • and well... many my previous issues are left unasweared

    Yes, they are, but isn't it much better to work on only one problem until it is solved, then go on to the next, instead of getting information overkill?

    wow. everyday i learn something new. never knew about such thing. how weird is that simitation O.o like - it can easly count 2 + 2 but have troubles with 0,2 + 0,2?

    It can, but we the bad, mean humans limitate it. We only give him a limited number of bits. But with a floating point number there are occasions where those bits are not enough to exactly represent the number, and so the processor jumps to the nearest possible representation.

    also - what the heck is int expression??? i never seen that before on both expresions and system expresions pages on wiki.

    http://sourceforge.net/apps/mediawiki/construct/index.php?title=System_Expressions

    You will find it under part 9: System

    It converts a string or a float to an integer by rounding down.

    the problem is, last frame suppose to be 100% ShieldEnergy only, just the first frame 0% should be displayed only when ShieldsCurrent hits 0%. with this the last frame 100% is for some reason never played, or should i say - it is but if ShieldCurrent is about 100% (100,000001% for example).

    The formula I wrote down is designed to show the shield status 100% only, if EnergyCurrent matches exactly EnergyTotal. On the other hand it displays the 0% frame also up until a certain amount (when using 11 frames everything below 10%)

    If you want to tweak its behavior, just replace 'int' by 'round' or 'ceil'. Ceil rounds up to the next integer, and round rounds to the nearest integer [=> round(1.49) = 1, round(1.5) = 2]

    If you use 'ceil' instead of 'int', then the 0% frame is only shown, if EnergyCurrent is exactly 0, whereas the 100% frame will be shown for every value above 90%.

    why my method doesnt work and why your does.

    Just because I have a small lead over you in programming. Just keep on doing and you will solve such problems by yourself with ease. Promised.

  • It seems, you want to present some kind of a shield status display. This display has 11 frames, representing 11 states of the shield status. Something like this:

    xxxxxxxxxx -> shield 100%

    xxxxxooooo -> shield 50%

    oooooooooo -> shield 0%

    Am I right? If so, there is a much simpler way achieving this. You have two values, EnergyTotal and EnergyCurrent. The first one is a value depending on the ship and its equipment. It may be 300 for one ship and 500 for another. If it was 300, then EnergyCurrent would have a start value of 300 and then lower whenever energy is used. And if EnergyCurrent is 150 it is 50% of EnergyTotal. But if the player now enhances the ship, the EnergyTotal may raise to 500. In result the 150 of EnergyCurrent represent no longer 50%, but 30%.

    If all of these assumptions are right, then you only need to do the following:

    + Always
    -> EjectorShieldBar: Set animation frame to int((EjectorShieldBar.GetAnimationFrameCount - 1) / global('Spaceship - EnergyTotal') * global('Spaceship - EnergyCurrent')) + 1[/code:1fpmigt2]
    
    Yes, you only need one event for all of your animation frames. The expression
    
    int((EjectorShieldBar.GetAnimationFrameCount - 1) / global('Spaceship - EnergyTotal') * global('Spaceship - EnergyCurrent')) + 1
    
    automatically sets the right frame in relation to the percentage from EnergyCurrent to EnergyTotal.
    
    [h2]EnergyTotal = 300
    EnergyCurrent = 300
    EjectorShieldBar.GetAnimationFrameCount = 11
    --> frame = int((11 - 1) / 300 * 300) + 1 = int(10 / 300 * 300) + 1 = 10 + 1 = 11
    
    EnergyTotal = 300
    EnergyCurrent = 0
    EjectorShieldBar.GetAnimationFrameCount = 11
    --> frame = int((11 - 1) / 300 * 0) + 1 = int(10 / 300 * 0) + 1 = 0 + 1 = 1
    
    EnergyTotal = 300
    EnergyCurrent = 150
    EjectorShieldBar.GetAnimationFrameCount = 11
    --> frame = int((11 - 1) / 300 * 150) + 1 = int(10 / 300 * 150) + 1 = 5 + 1 = 6
    
    EnergyTotal = 500
    EnergyCurrent = 150
    EjectorShieldBar.GetAnimationFrameCount = 11
    --> frame = int((11 - 1) / 500 * 150) + 1 = int(10 / 500 * 150) + 1 = 3 + 1 = 4
    
    EnergyTotal = 500
    EnergyCurrent = 150
    EjectorShieldBar.GetAnimationFrameCount = 21
    --> frame = int((21 - 1) / 500 * 150) + 1 = int(20 / 500 * 150) + 1 = 6 + 1 = 7[/h2]
    
    You may change every value (including the number of frames you use in your animation to represent the status), it will always show the correct status of the ships shield.
  • whats wrong with this?

    clamp(global('Spaceship - EnergyTotal'),global('Spaceship - EnergyTotal')*0.6,global('Spaceship - EnergyTotal')*0.69)[/code:1v2oqfvx]
    

    There's nothing wrong with it. It just doesn't make sense. The returned value of this expression will always conform to global('Spaceship - EnergyTotal') * 0.69.

    clamp returns a bounded value. But, if you make the bounds relative to the value, it will always return the highest or lowest value, depending on the relation. Just replace global('Spaceship - EnergyTotal') with a value to see the problem. Let's say, global('Spaceship - EnergyTotal') equals 100:

    clamp(100,100*0.6,100*0.69)

    You're now ordering Construct to return 60, if the original value is lower than 60, to return the original number, if it is between 60 and 69, and to return 69, if the original value is greater than 69. But the original value always is 100, and so you are always getting 69.

    And now think of all the different values, global('Spaceship - EnergyTotal') may have. They all will be greater than global('Spaceship - EnergyTotal') * 0.69

    clamp(50,50*0.6,50*0.69) will return 34.5 (always and only)

    clamp(260,260*0.6,260*0.69) will return 179.4 (always and only)

    So, if you are comparing global('Spaceship - EnergyCurrent') with clamp(global('Spaceship - EnergyTotal'),global('Spaceship - EnergyTotal')*0.6,global('Spaceship - EnergyTotal')*0.69), you are comparing global('Spaceship - EnergyCurrent') with global('Spaceship - EnergyTotal')*0.69

    This comparison will only be successful, if global('Spaceship - EnergyCurrent') conforms exactly to global('Spaceship - EnergyTotal')*0.69, and not to a range of values.

    Don't make the bounds of clamp relative to its value. And, if you want global('Spaceship - EnergyCurrent') to be in a certain range for the condition to become true, do this:

    + Is global variable 'Spaceship - EnergyCurrent' greater or equal global('Spaceship - EnergyTotal') * 0.6
      Is global variable 'Spaceship - EnergyCurrent' less or equal global('Spaceship - EnergyTotal') * 0.69
    [/code:1v2oqfvx]
    That's two conditions in one event, meaning they both need to be true for the action to be performed. And they are both true for [i]every[/i] value between global('Spaceship - EnergyTotal') * 0.6 and global('Spaceship - EnergyTotal') * 0.69
  • actualy i was just an idiot and though that if i write % mark it would (just as using your calculator) divide. forgoten this obvious fact that 10% are in fact 0.10, and to get 10% of something i need it be multiply by 0.10.

    Don't be too harsh to yourself. It's just learning by doing, we all come to such points from time to time

    * off-topic *

    And here a description of the modulo operation:

      The percentage sign, when used outside of a string, is an operator, just like +, -, *, /, etc. And it does divide, but a modulo division, aka 'mod', giving the integer remainder of the division:
        13 % 5 = 3 -> can also be expressed by: 13 - floor(13 / 5) * 5 -> you can also do ((13 / 5) - floor(13 / 5)) * 5 -> it is just returning the decimal places of the division multiplied by the denominator
          13 / 5 = 2.6; 0.6 * 5 = 3
      Modulo is often used in programming to get a repeating list of ordered numbers. For example, the timer returns the milliseconds passed since start of the application. You want a sprite to constantly fade in and out repeatedly and every fade should last 1 second. But the sprite's opacity is expressed by a value ranging from 0 to 100. So what we need is converting the timer value in a way that we get a value repeatedly growing and shrinking between 0 and 100.
      • There are 1000 milliseconds in one second, but we need one second to be 100.
      • If doing 'timer % 100', the results returned will raise from 0 to 99, then immediatly fall back to 0 and raise again. [0, 1, 2, ..., 98, 99, 0, 1, 2, ...]
      The first issue is solved by floor-dividing timer by 10. The second issue is solved with two other tricks. First, we set the denominator to 201. This way the values returned will range from 0 to 200. Second, we make use of 'abs', which returns the absolute value of a number regardless of its sign (-4 and 4 both have the absolute value 4) The final expression now is: opacity = abs(100 - floor(Timer / 10) % 201) The returned values will be [100, 99, 98, ..., 2, 1, 0, 1, 2, ..., 98, 99, 100, 99, 98, ...] and every range 0-100 or 100-0 will last 1 second

    I just thought I explain it for those who are curious beginners. If it is inappropiate, I apologize.

  • You have two conditions on 6. Else means run if the tied condition is not met, so another condition saying not to run causes the error.

    Not necessarily, no. Something like this works fine:

    + n equals 6
    
    + else
       n equals 5
    
    + else
       n equals 4
    
    + else[/code:2uqm8xa8]
    
    But there is another possible problem. Are you trying to modulo divide by 0? That's not possible (although I expected Construct to catch such error)