Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-03-2011, 07:47 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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";
    
screenwidth width 2;
    
screenheight height 2;
    
alpha 1;

    new 
GuiScrollCtrl("Generated_MultiLine_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 249;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 300;
      
0;
      
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";
    
screenwidth width 2;
    
screenheight height 2;

    new 
GuiTextEditCtrl("Generate_Encode") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 137;
      
7;
      
23;
    }
    new 
GuiTextCtrl("Generate_Text") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Enter the text to encode!";
      
width 139;
      
6;
    }
    new 
GuiButtonCtrl("Generate_Generate") {
      
profile GuiBlueButtonProfile;
      
text "Generate";
      
width 137;
      
7;
      
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 ">";

__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #2  
Old 11-03-2011, 08:20 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by Gunderak View Post
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.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #3  
Old 11-03-2011, 08:48 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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!
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #4  
Old 11-03-2011, 09:42 AM
oo_jazz_oo oo_jazz_oo is offline
Jazz teh Awesome
oo_jazz_oo's Avatar
Join Date: Jul 2006
Location: California
Posts: 596
oo_jazz_oo is a jewel in the roughoo_jazz_oo is a jewel in the rough
Send a message via MSN to oo_jazz_oo
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 "'>"
__________________

Reply With Quote
  #5  
Old 11-03-2011, 11:04 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 07:40 PM.


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