Control BackImage using variable value

xabileug

Veteran
Veteran
Joined
Jul 1, 2014
Messages
103
Reaction score
21
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,278
Reaction score
544
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
103
Reaction score
21
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
103
Reaction score
21
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 Posts

Latest Profile Posts

Discovering math. functions for damage formulas was one of the greatest things for me.
It's very useful for balancing skills to work in a variety of possible circumstances.
For example if you have a skill that is supposed to work for both mages and warriors:
Code:
Math.max(a.atk * 2 - b.def, a.mat * 2 - b.mdf)
SpaceX: First-ever successful (manned) commercial spaceflight!! In these terrible and self-sabotaging times for the world, that's a ray of excitement and hope I needed badly.
GameDevJohn wrote on whtdragon's profile.
Hey I used you bunny and cat spritesheet for a game jam game. Thanks so much! You have really beautiful stuff here. I'll credit you at https://gamedevjohn.itch.io/bunny-boy
The video of a psycho chasing people on the streets with a sword before getting subdued is wild. Apparent screenshots of his Twitter feed (EDIT: confirmed by Dallas police) before it went private reveal a dangerous delusional mindset. I heard there was a bow person too. The crazies are really coming out of the woodworks.

Forum statistics

Threads
98,016
Messages
948,564
Members
129,275
Latest member
Descent89
Top