Control BackImage using variable value

xabileug

Veteran
Veteran
Joined
Jul 1, 2014
Messages
107
Reaction score
22
I want to change the back image of a custom scene depending on the value of the variable. I made the input part here..

JavaScript:
/*
* @param CardBattle BackImages
* @desc set backimage depending on variable
* @type struct<backImage>
* @default {"images":"[]","vnBackImages":"0"}
* @parent dataType
*/

//=============================================================================
/*~struct~backImage:
* @param images
* @desc set image per variable value
* @type file[]
* @default []
* @require 1
* @dir img/pictures
* @parent otherType
*
* @param vnBackImages
* @desc set variable ID control
* @type variable
* @default 0
* @parent database
*/

but when i apply it on the part where the createBackground is.. nothing happens.. here's the code.

JavaScript:
Spriteset_CardBattle.prototype.createBackground = function() {
        this._backgroundSprite = new Sprite();
        var abc  = TMPlugin.Card.SBI.cardbattle;
        var index = abc.vnBackImages ? $gameVariables.value(abc.vnBackImages) - 1 : 0;
        var bgiName = index >= 0 ? abc.images[index] : null;
        this._backgroundSprite.bitmap = bgiName ?
            ImageManager.loadPicture(bgiName) : ImageManager.loadPicture('cardbattle');
        this._baseSprite.addChild(this._backgroundSprite);

    };

I think it is because i don't know how to properly call the parameters? i used a hashkey (i think)

JavaScript:
    TMPlugin.Card.SBI = {
        cardbattle : {images:[],vnBackImages:0},
    };

Thank you.
 
Last edited:

Eliaquim

Raze: The Rakuen Zero's Guardian!
Veteran
Joined
May 22, 2018
Messages
1,285
Reaction score
545
First Language
Portuguese - Br
Primarily Uses
RMMV
About the parameters, take a look at this and see if it helps.
 

xabileug

Veteran
Veteran
Joined
Jul 1, 2014
Messages
107
Reaction score
22
Hello. Thank you for the reply. I viewed your link..

i have the parse code too..
JavaScript:
(function() {
    // new line

    var parameters = PluginManager.parameters('TM_Card');

    var paramParse = function(obj) {
        return JSON.parse(JSON.stringify(obj, paramReplace));
    };

    var paramReplace = function(key, value) {
        try {
            return JSON.parse(value || null);
        } catch (e) {
            return value;
        }
    };

    var setBackImages = function(param) {
        param = paramParse(parameters[param]);
        return param instanceof Object ? param : {images:[],vnBackImages:0};
    };

    TMPlugin.Card.SBI = {
        cardbattle : setBackImages('CardBattle BackImages'),
    };
 // new line end
But then it's not being fetched properly.. i still get 'cardbattle' the default value in the bolean as image..
 

xabileug

Veteran
Veteran
Joined
Jul 1, 2014
Messages
107
Reaction score
22
i got this to work. I think the error was the line

Code:
var parameters = PluginManager.parameters('TM_Card');

//switched to
//var parameters = PluginManager.parameters('TMCard');
I also replaced vnBackImages to variableId

so im trying to use the same logic with variable controlled BGM.. i cant find where the event > system settings > change Battle BGM is located.. so i made this code to change the battle bgm

Code:
        var abc  = TMPlugin.SBM.cardmusic;
        var index = abc.variableId ? $gameVariables.value(abc.variableId) - 1 : 0;
        var bgmName = index >= 0 ? abc.name[index] : null;
        var bgm = {"name":bgmName,"pan":abc.pan,"pitch":abc.pitch,"volume":abc.pitch};
        if (bgmName !== null){
        AudioManager.playBgm(bgm);
        } else {
        BattleManager.playBattleBgm();
        }
i get the error Audiomanager not defined.
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

So in my stream for the No Travel Game Jam, I mentioned we were going to do a teaching make a game from beginning to end series of streams, but it had to wait on an announcement I couldn't make yet before I could start... Keep your eyes on our twitter tonight.
Surprise extra Text Adventure session! Feel free to drop by!
I just started parallax mapping. Better results for sure, but a lot more time consuming. It's more fun than I thought though.
After a bit of away time due to virus and friends in crisis (friends get priority!) I think things have calmed enough for me to try to resume my activity everywhere. :kaoluv:(I still been working on projects though!)
After watching 'Whisper Of The Heart' I've got the song 'Country roads' stuck in my head.
Don't mind it so much as that I was singing today at my Church. :kaoswt:

Forum statistics

Threads
98,114
Messages
949,385
Members
129,392
Latest member
starshot90
Top