Can You Save A Sprite's Effect Value to a Global Variable?

0 favourites
  • 12 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • I'll try and explain the best I can what I'm looking to do..

    So say I have a white sprite, I give it the tint effect and a color '140, 176, 136'

    I want to be able to click it and have it's value - rgb(140, 176, 136) stored in a global variable.

    Is there anyway to do this?

    The reason I want to do it is so I could just refer to a colour as (for example)

    Global Number Item_Color = 1

    and then the item in question could see the item_color number and associate it with the rgb value that's also stored in a variable rather than have to hand code each rgb value for many sprites I intend to want to be able to customise the color of.

    I hope that's explained my question I'd appreciate any advice here

    Tagged:

  • I kind of get what you're asking but I don't quite grasp the reasoning behind it, it's for more efficient events? I know how to assign an rgb or colour to a sprite based on a global variable, as for extracting the rgb from a sprite, I'm not sure if that is possible of if it's needed. There is probably an easy way of doing what you want, how does the game work with the colour setting?

  • Thanks for the reply, I guess another explanation would be, I want to go back and forward through different layouts and have a sprite ‘rememebr’ It’s effect parameters

    So if you say it is possible to set it via a globe variable I could set that when setting the colour then when loading the layout get it back from there.. how would I go about doing that?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you know in advance what you want to set it to like you are describing here then you could set the global variable to a string i.e. "140,176,136" then on object clicked set colour to rgbEx(int(tokenat(variable1,0,",")),int(tokenat(variable1,1,",")),int(tokenat(variable1,2,",")))

    It may look scary but this is just splitting out the 3 numbers in the string and setting the rgb parameters to each number, where 'variable1' is the global variable. But yeah, this may be the reverse of what you want.

  • What plinkie posted is what I would do as well ^

    However, make sure you use rgbEx255 instead of RgbEx. RgbEx uses 0-100 instead of 0-255

    rgbEx255(int(tokenat(variable1, 0, ",")),int(tokenat(variable1, 1, ",")),int(tokenat(variable1, 2, ",")))

  • Ok thanks guys I’ll try that out :)

  • Well it defiantly helped in terms of the sprite being able to keep the same color from layout to layout which is great.. I'm just left wondering if it's possible at all to get the effect value into that variable without me explicitly re-typing it.

    Here's a link to a basic sample project

    https://www.dropbox.com/s/b5rauqmuidlxwnw/ColorTests.c3p?dl=0

    I only use one single sprite here 'Ball' with different instance variables to say which color should trigger when clicked and yes I can do what I did here which is to re-type the tint color again:

    but it would just be a big time saver with more colours if I could some how say, pick the sprite with the specific instance variable and get it's tint value and put it into the variable - if it's not possible I understand and can still work with the advice I've been given.. It just seemed odd to me that I could get a bunch of other information from a sprite but not the effect value

  • Because I don't know how to extract rgb and not sure if possible, the best I can do to minimize the code is this, where you go into the layout and set 3 instance variables on the ball to its rgb. Maybe that helps, it does avoid typing them all out in the event sheet. :)

    dropbox.com/s/dbyrzpar6agrp6r/ColorTests.c3p

  • Maybe I don't get it, but isn't it easier to put the rgb value in on variable as number and set this one variable back as parameter for the tint-effect?

    ...-> System: Set BallColor to rgbEx255(140, 176, 136)

    ...-> Ball: Set effect "Tint" parameter 0 to BallColor

  • Those 3 values were an example, in the game they are unknown so you have to set ballcolor to rgb(of a sprite). Maybe someone knows how to extract those values, but I fixed it the other way :P

  • Thanks plinkie!

    It does seem to do what I want in this small test project, I'll have to try to integrate it into my main project and see if it still works, but I don't see why it shouldn't :D

  • This worked as close to perfectly as I could have expected without the direct 'get effect value' option so thanks again :)

    Just curious but I'm just using the 'rgb(64, 45, 41)' to set the value, does it matter that it doesn't state either EX or EX255? kidswithcrowns

    However, make sure you use rgbEx255 instead of RgbEx. RgbEx uses 0-100 instead of 0-255

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)