Is there any way to show picture from url link? In order to show news abou the game to the players
Is there any way to show a pictures from url
RPG Maker MV SupportYes, it's possible. You can do it using the following snippet. Note that I did not write it. I merely dug through stack exchange and put it together and so, no need to credit me. Save this as a .js file and put it inside js/plugins and turn it ON in the plugin manager. You can call it with
Example:
This will save the google logo to the pictures folder inside img folder as test.png
Every time the function is called, the image will be redownloaded so you can easily replace the file in the link. I guess if you keep the image in github as public, then the link will be same even if you replace the image. Idk, you have to think that through. And you can show it using the show picture command or script call if needed.
Reference:
Getting the image data(2nd reply)
Saving the image data
img.save(url,destination)Example:
img.save("https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png","img/pictures/test.png");This will save the google logo to the pictures folder inside img folder as test.png
Every time the function is called, the image will be redownloaded so you can easily replace the file in the link. I guess if you keep the image in github as public, then the link will be same even if you replace the image. Idk, you have to think that through. And you can show it using the show picture command or script call if needed.
JavaScript:
/*url= The url of the image.
//dest= Where you want to save the image.
Example:img.save("https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png","img/pictures/test.png");
This will save the google logo to the pictures folder inside img folder as test.png
*/
class img {
static save(url, dest) {
function toDataUrl(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var reader = new FileReader();
reader.onloadend = function() {
callback(reader.result);
}
reader.readAsDataURL(xhr.response);
};
xhr.open('GET', url);
xhr.responseType = 'blob';
xhr.send();
}
toDataUrl(url, function(data64) {
console.log(data64);
var fs = require('fs');
var img = data64;
var data = img.replace(/^data:image\/\w+;base64,/, "");
var buf = new Buffer(data, 'base64');
console.log(buf);
fs.writeFileSync(dest, buf);
});
}
}
Getting the image data(2nd reply)
Saving the image data
First of all thanks for your attention!
I downloaded as imgurl.js and used command script :
img.save(https://raw.githubusercontent.com/Decinbr/FW-Updater/master/GGolem(1).png,"img/pictures/test.png")
But nothing happened.
And how i will put the img on right place of the screen? coordenates and so on.
I downloaded as imgurl.js and used command script :
img.save(https://raw.githubusercontent.com/Decinbr/FW-Updater/master/GGolem(1).png,"img/pictures/test.png")
But nothing happened.
And how i will put the img on right place of the screen? coordenates and so on.
You've made a mistake. The url will be inside "".
Correction:
img.save("https://raw.githubusercontent.com/Decinbr/FW-Updater/master/GGolem(1).png","img/pictures/test.png")
After that, it should currently be in your pictures folder named as test.png. You have to manually show it using the 'show picture' command. The idea is to download the image first and then show it so this script call will download it and then you have to show it.
Btw, can you give me more info about what you're trying to do? I think there can be better solutions for your problem if you elaborate a bit.
Correction:
img.save("https://raw.githubusercontent.com/Decinbr/FW-Updater/master/GGolem(1).png","img/pictures/test.png")
After that, it should currently be in your pictures folder named as test.png. You have to manually show it using the 'show picture' command. The idea is to download the image first and then show it so this script call will download it and then you have to show it.
Btw, can you give me more info about what you're trying to do? I think there can be better solutions for your problem if you elaborate a bit.
Worked like a charm! Thanks for your life!
One more doubt... Can i show a message from github and be showed inside game?
One more doubt... Can i show a message from github and be showed inside game?
A text file? Yeah, you can. I'm getting ready to sleep so can't test it out but this code is pretty straightforward.
stackoverflow.com
See the first reply. If you have problems, I'll try to help tomorrow or maybe someone else can.
HTML - read .txt file from URL location in javascript
I want to read a .txt file an URL location, lets say from http://www.puzzlers.org/pub/wordlists/pocket.txt and process its content on my page. Can you point me out some tutorials or some basic co...
I will wait you, because im newbie on these things. I am immensely grateful to you!!
I'm not good with js either but I can frankencode parts together XD
So this is what I managed to do. You can paste this under the previous snippet I posted or make a new .js file with only this.
Example of usage:
This will set the text in that text file in game variable 1.
Btw, note that getting text takes time so you have to include a wait between calling this function and and showing the text. Otherwise, you won't get the text. It can be from 10-60 frames depending on how big the text is. For images too, you have to include the wait and I've seen instead of show text command, script call works better in this case for some reason.
This is quite inconvenient but I don't know any other way. You could request for a full plugin instead of these tiny snippets in the plugin requests section for better solutions.
So this is what I managed to do. You can paste this under the previous snippet I posted or make a new .js file with only this.
JavaScript:
class text {
static set(variable, url) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.onload = function() {
$gameVariables.setValue(variable, xhr.responseText);
}
xhr.send();
}
}
text.set(1,"https://12Me21.github.io/test.txt");This will set the text in that text file in game variable 1.
Btw, note that getting text takes time so you have to include a wait between calling this function and and showing the text. Otherwise, you won't get the text. It can be from 10-60 frames depending on how big the text is. For images too, you have to include the wait and I've seen instead of show text command, script call works better in this case for some reason.
I got this error...
Its me again lol.
Is working in my project editor, but when i deploy the game to windows i get this error...
Is working in my project editor, but when i deploy the game to windows i get this error...
Original thread: https://forums.rpgmakerweb.com/threads/is-there-any-way-to-show-a-pictures-from-url.131860/