Changing an image file in game via scripting.

  • #1, by dos4gwSaturday, 25. April 2015, 21:41 9 years ago
    I'm working on a game that has two playable characters. Each of these characters has their own distinct backdrop for their inventory.

    I'd like to know if there is a way I could replace an image file on a GUI object in game via scripting. I know, just creating a second object of the backdrop and switching between the two would be the most ideal, but the script we have for the inventory is fairly complicated, I'm the world's worst scripter, and the team member who created the thing is no longer with us.

    Any help would be much appreciated. Thanks.

    Newbie

    69 Posts


  • #2, by afrlmeSaturday, 25. April 2015, 23:13 9 years ago
    I can take a look if you like?

    & yes having the images as a buttons / objects would be the simplest solution. I assume the interfaces are the same size? & the placements are all in the same place?

    Imperator

    7278 Posts

  • #3, by dos4gwSunday, 26. April 2015, 00:13 9 years ago
    Below is the script. The line in question is local inventoryBack = getObject("Interfaces[InventoryBackdrop]")

    I would like to have, say, an inventoryBack for my first character and then an inventoryBack2 for the second character, but I can't figure out what to put in there to switch them out depending on the current character.

    No other parts of the inventory need to change, just the stuff pertaining to the backdrop images.

    [quote

    Newbie

    69 Posts

  • #4, by afrlmeSunday, 26. April 2015, 01:38 9 years ago
    Ah I see. I believe the quickest solution for you would be to create a transparent png at the same size as the background image. Add the transparent png (or webp) image as the background image. Next create a button & set the button type to action area. Now add your two different backgrounds to the button. One to inactive image & the other to active. Then it will be as simple as toggling the active state of the button, which you could do in the same action block(s) you use for setting your characters.

    Alternatively you could do it by editing various sections of the script, or by writing a new function. I think the solution I wrote above would be the simplest approach for you though.

    P.S: you should have used code tags note quote tags, so that it kept the correct nesting, rather then aligning each line to the left.

    Imperator

    7278 Posts

  • #5, by dos4gwSunday, 26. April 2015, 02:10 9 years ago
    That did it! Thanks so much grin

    Newbie

    69 Posts