- Joined
- Mar 28, 2016
- Messages
- 1,623
- Reaction score
- 1,439
- First Language
- French
- Primarily Uses
- RMMV
Hi guys, what is the best way to pass a no static variable for a callback inside a loop ??
ex: How to (fixing) a dynamic variable in a loop, and inject it into a CallBack
in this example if i pass i, its take only the i valur of the end loop.
How i can give static valur of i in the callback ?
Tank a lot for help.
In ES6 , it seems so simple & easy... !!!
ex: How to (fixing) a dynamic variable in a loop, and inject it into a CallBack
Code:
for (var i=0,R=0,C=0;i<ItemPage.length;i++,C++){
$image.showPicture(PID++, 'M_Item_ItemSlot_Shader', 0, this.d2d2d2[0]+(this.ITDxy[0]*C), this.d2d2d2[1]+(this.ITDxy[1]*R), 100, 100, 255, 0);
$image.setPictureTrigger(PID-1, "Mouse Out", function(pictureId){ that.HoverOutItem(pictureId); });
$image.setPictureTrigger(PID-1, "Left Click", function(pictureId,i){ that.ClickItem(pictureId,i); }); // i whant pass i in this callback *****
if((i+1)%4===0){C=-1,R++}
}
How i can give static valur of i in the callback ?
Code:
$image.setPictureTrigger(PID-1, "Left Click", function(pictureId,i){ that.ClickItem(pictureId,i); }); // i whant pass i in this callback *****
In ES6 , it seems so simple & easy... !!!
Code:
for (let i = 0; i < 3; i++) {
funcs[i] = function() {
console.log("My value: " + i);
};
}
Last edited:

