Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   QR Code Generator Problem (https://forums.graalonline.com/forums/showthread.php?t=134264959)

Gunderak 11-03-2011 07:47 AM

QR Code Generator Problem
 
I have recently been playing around with googles API for generating QR codes and have thought, hey why not make one in graal.
So I went on my merry way to script it and this is what I have so far, but theres one huge problem... It doesnt display the image, instead it displays some sort of Binary Dump, any suggestions are appriciated.
In case you do not know what a QR code is click here and it will explain it in greater depth, its a 2D image that stores Binary and can be read extremly fast, it was designed for car parts originally but when they realised how powerful it was they then went on to use it for alot more.
Im not even sure if this task can be achieved in the boundaries of GS2 but hey, its worth a shot.

My Script..
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
Generate_Window.destroy();
  
Generated_Window.destroy();
}

function 
onPlayerChats() {
  if (
player.chat == "/generate") {
    if (
Generate_Window.visible == "1") {
      
Generate_Window.destroy();
      return;
    }
    
CreateGenGUI();
  }
}

function 
CreateGeneratedGUI() {
  new 
GuiWindowCtrl("Generated_Window") {
    
profile = GuiBlueWindowProfile;
    
clientrelative = true;
    
clientextent = "300,  250";

    
canclose = true;
    
canmaximize = false;
    
canminimize = false;
    
canmove = false;
    
canresize = false;
    
closequery = false;
    
destroyonhide = false;
    
isexternal = false;
    
text = "Generated QR Code";
    
x = screenwidth / 2 - width / 2;
    
y = screenheight / 2 - height / 2;
    
alpha = 1;

    new 
GuiScrollCtrl("Generated_MultiLine_Scroll") {
      
profile = GuiBlueScrollProfile;
      
height = 249;
      
hscrollbar = "dynamic";
      
vscrollbar = "dynamic";
      
width = 300;
      
x = 0;
      
y = 0;

      new 
GuiMLTextCtrl("Generated_MultiLine") {
        
profile = GuiBlueMLTextProfile;
        
height = 231;
        
horizsizing = "width";
        
text = "<center><br><br><br><br><br>Generating QR Code.<br>Please wait.";
        
width = 296;
      }
    }
  }
}

function 
CreateGenGUI() {
  new 
GuiWindowCtrl("Generate_Window") {
    
profile = GuiBlueWindowProfile;
    
clientrelative = true;
    
clientextent = "150,82";

    
canclose = false;
    
canmaximize = false;
    
canminimize = false;
    
canmove = true;
    
canresize = true;
    
closequery = false;
    
destroyonhide = false;
    
text = " QR Code Generator";
    
x = screenwidth / 2 - width / 2;
    
y = screenheight / 2 - height / 2;

    new 
GuiTextEditCtrl("Generate_Encode") {
      
profile = GuiBlueTextEditProfile;
      
height = 20;
      
width = 137;
      
x = 7;
      
y = 23;
    }
    new 
GuiTextCtrl("Generate_Text") {
      
profile = GuiBlueTextProfile;
      
height = 20;
      
text = "Enter the text to encode!";
      
width = 139;
      
x = 6;
    }
    new 
GuiButtonCtrl("Generate_Generate") {
      
profile = GuiBlueButtonProfile;
      
text = "Generate";
      
width = 137;
      
x = 7;
      
y = 48;
    }
  }
}

function 
Generate_Generate.onAction() {
  if (
Generate_Encode.text != null) {
    
Generated_Window.destroy();
    
Generate_Window.destroy();
    
CreateGeneratedGUI();
    
Generated_MultiLine.text = "<center><br><br><br><br><br>Generating QR Code.<br>Please wait.";
    
temp.req = requesturl("http://chart.apis.google.com/chart?chs=150x150&cht=qr&chld=L|0&chl=" @ Generate_Encode.text @ "");
    
this.catchevent(temp.req, "onReceiveData", "onSiteDownloaded");
  }
}

function 
onSiteDownloaded(obj) {
  
Generated_MultiLine.text = "<img src=" @ obj.fulldata @ ">";
} 


Tolnaftate2004 11-03-2011 08:20 AM

Quote:

Originally Posted by Gunderak (Post 1672899)
It doesnt display the image, instead it displays some sort of Binary Dump, any suggestions are appriciated.

Well, you are requesting a png image from the web and then using the file contents as the image source (or trying, I don't know how well GUI controls handle HTML), which is dun dun dun a binary file.

Might try <img src="http://chart.api.google.com/..." />, and may have to use some other tricks to get it to display.

Gunderak 11-03-2011 08:48 AM

Thanks for trying to help, but it still doesnt work :/
In the mean time while waiting, I have made one for iDevices xD
scripters.99k.org for the demo, it isnt completly done but still works..
If only apple would allow the uploading of files..
I could make a QR Reader in PHP.
Darn you apple!

oo_jazz_oo 11-03-2011 09:42 AM

I dont understand why you're using requesturl for this.

PHP Code:

http://chart.apis.google.com/chart?chs=150x150&cht=qr&chld=L|0&chl= 

Is an image.

So you could just simple do when the button is pressed, just have
PHP Code:

Generated_MultiLine.text = "<img src='http://chart.apis.google.com/chart?chs=150x150&cht=qr&chld=L|0&chl=" @ Generate_Encode.text @ "'>"; 


Gunderak 11-03-2011 11:04 AM

I thought because it's an external page you would have to request it.
Would doing it how you said make it work?
I cannot test because I am not at home.


All times are GMT +2. The time now is 01:15 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.