Jump to content
UBot Underground

Convert variable value from HEX format to RGB format?


Recommended Posts

I'm looking for a hopefully simple way to convert a variable's value from a HEX value, to it's RGB equivalent. 

 

IE if user inputs #ff8800 in the input field, let's say #colorA. I want to automatically convert that to it's RGB value.  In this case, #colorA would automatically become 255,136,0  which is the RGB value for the above Hex.

 

I know there are various equations out there but I haven't the slightest clue how to get them into uBot and make them work for this.

Link to post
Share on other sites

I'm looking for a hopefully simple way to convert a variable's value from a HEX value, to it's RGB equivalent. 

 

IE if user inputs #ff8800 in the input field, let's say #colorA. I want to automatically convert that to it's RGB value.  In this case, #colorA would automatically become 255,136,0  which is the RGB value for the above Hex.

 

I know there are various equations out there but I haven't the slightest clue how to get them into uBot and make them work for this.

 

I wouldn't say it is an impossible task at all.

Here is what I would do:

 

1. Find the most understandable of the "various equations out there" that you mention above

2. Break down the equation you found in #1 above into several mathematical steps.

3. Write a UBOT command for each of the steps you defined in #2 above.

4. Display or use the results of #3.

 

If you show us the equation you want to solve here I bet you'll get some coding help.

 

Good luck, Andy (Arunner26)

Link to post
Share on other sites

You have gave up after 30 minutes? Almost everything is possible, you just need to believe and maybe put some more effort into it....

 

I think the simplest way would be to find some javascript for that and use UBot's $eval function to execute the javascript and return result.

Link to post
Share on other sites

I've been trying for like a week lol.

 

I went through all the Google searches, but being someone who is not knowledgable in Javascript enough to pick apart the scripts and put them back together puts me at a blank.

 

I mean none of those scripts set ubot variables, which would be the most important aspect and unfortunately I don't know how to get those javascript snippets to set Ubot variables (or retrieve the existing variables that need to be converted), especially since I have many separate input fields that need to be converted.

Link to post
Share on other sites

I've been trying for like a week lol.

 

I went through all the Google searches, but being someone who is not knowledgeable in JavaScript enough to pick apart the scripts and put them back together puts me at a blank.

 

I mean none of those scripts set ubot variables, which would be the most important aspect and unfortunately I don't know how to get those javascript snippets to set Ubot variables (or retrieve the existing variables that need to be converted), especially since I have many separate input fields that need to be converted.

 

I have found the botters on this forum are usually very helpful.

I suggest that you post more technical details about the issues you are grappling with and see what happens.

Most of the time when I see people here not making progress here it is when they don't post enough details.

Give specific questions and get specific answers.

Do you have a JavaScript you would like to convert into UBOT?

Link to post
Share on other sites

I have found the botters on this forum are usually very helpful.

I suggest that you post more technical details about the issues you are grappling with and see what happens.

Most of the time when I see people here not making progress here it is when they don't post enough details.

Give specific questions and get specific answers.

Do you have a JavaScript you would like to convert into UBOT?

 

Yea, I'm not the best explainer of my issues lol.

 

My specific question is:  How to convert a variable whose value is a hex code, to the RGB form of that samehex value.

 

Example, if #colorA has a value of #ff8800, the script would change that value would become 255,136,0.  Now #colorA would have a value of 255,136,0 instead of #ff8800

Link to post
Share on other sites

If you would at least try to do what I have told you, I'm sure you would already have a solution. There is actually no javascript knowledge needed  to implement this (since you only need to copy the script from one of those pages and you only need to know that a (JavaScript) function returns a value, which is true for all of the programming languages btw), so it's mostly UBot knowledge that's left.

 

It looks like you don't have any desire to learn this, so I'll just post an example for you (although I think it would be better if you would get to these results on your own, since that way you would learn something and remember that for always):

run javascript("function hexToR(h) \{return parseInt((cutHex(h)).substring(0,2),16)\}
function hexToG(h) \{return parseInt((cutHex(h)).substring(2,4),16)\}
function hexToB(h) \{return parseInt((cutHex(h)).substring(4,6),16)\}
function cutHex(h) \{return (h.charAt(0)==\"#\") ? h.substring(1,7):h\}")
ui text box("COLOR Hex:", #COLOR Hex)
set(#COLOR R, $eval("hexToR(\"{#COLOR Hex}\");"), "Global")
set(#COLOR G, $eval("hexToG(\"{#COLOR Hex}\");"), "Global")
set(#COLOR B, $eval("hexToB(\"{#COLOR Hex}\");"), "Global")

The JavaScript snippet used above can be found here: http://www.javascripter.net/faq/hextorgb.htm

  • Like 1
Link to post
Share on other sites

If you would at least try to do what I have told you, I'm sure you would already have a solution. There is actually no javascript knowledge needed  to implement this (since you only need to copy the script from one of those pages and you only need to know that a (JavaScript) function returns a value, which is true for all of the programming languages btw), so it's mostly UBot knowledge that's left.

 

It looks like you don't have any desire to learn this, so I'll just post an example for you (although I think it would be better if you would get to these results on your own, since that way you would learn something and remember that for always):

run javascript("function hexToR(h) \{return parseInt((cutHex(h)).substring(0,2),16)\}
function hexToG(h) \{return parseInt((cutHex(h)).substring(2,4),16)\}
function hexToB(h) \{return parseInt((cutHex(h)).substring(4,6),16)\}
function cutHex(h) \{return (h.charAt(0)==\"#\") ? h.substring(1,7):h\}")
ui text box("COLOER Hex:", #COLOER Hex)
set(#COLOR R, $eval("hexToR(\"{#COLOER Hex}\");"), "Global")
set(#COLOR G, $eval("hexToG(\"{#COLOER Hex}\");"), "Global")
set(#COLOR B, $eval("hexToB(\"{#COLOER Hex}\");"), "Global")

The JavaScript snippet used above can be found here: http://www.javascripter.net/faq/hextorgb.htm

 

It's not at all that i don't want to learn, I've been trying to pick apart codes for almost 7 days now, to no avail.  And have been using Ubot since it's inception, and can do some failry advanced.  It is not my effort, it is my lack of knowledge of javascript.  And I hadn't noticed that you had already posted that code.

 

I copied and pasted your code as so.

 

ui text box("COLOER Hex:", #COLOER Hex)

 

define hex to rgb {

    run javascript("function hexToR(h) \{return parseInt((cutHex(h)).substring(0,2),16)\}

function hexToG(h) \{return parseInt((cutHex(h)).substring(2,4),16)\}

function hexToB(h) \{return parseInt((cutHex(h)).substring(4,6),16)\}

function cutHex(h) \{return (h.charAt(0)==\"#\") ? h.substring(1,7):h\}")

    set(#COLOR R, $eval("hexToR(\"{#COLOER Hex}\");"), "Global")

    set(#COLOR G, $eval("hexToG(\"{#COLOER Hex}\");"), "Global")

    set(#COLOR B, $eval("hexToB(\"{#COLOER Hex}\");"), "Global")

}

 

 

It doesn't set any of the RGB values for some reason when I run the define. :(

Link to post
Share on other sites

I also tried adding that Javascript within the HEAD tags of the UIHTML panel, rather than in a run javascript function, then put the set commands in a define command.  I ran the define command and according to the debugger it still didn't want to set the R G and B values.

 

This is the javascript as it's entered in the HEAD tags;  (I have to add javascript to the UIHTML via pre-set variables because the {} symbols break any variables used in the UI HTML panel.)

 

set(#HexToRGBJavascript, "<script>
function hexToR(h) \{return parseInt((cutHex(h)).substring(0,2),16)\}
function hexToG(h) \{return parseInt((cutHex(h)).substring(2,4),16)\}
function hexToB(h) \{return parseInt((cutHex(h)).substring(4,6),16)\}
function cutHex(h) \{return (h.charAt(0)==\"#\") ? h.substring(1,7):h\}
</script>", "Global")
 

 

My test define is as follows:

 

define Hex to RGB {
    set(#COLOR Hex, "ff8800", "Global")
    set(#COLOR R, $eval("hexToR(\"{#COLOR Hex}\");"), "Global")
    set(#COLOR G, $eval("hexToG(\"{#COLOR Hex}\");"), "Global")
    set(#COLOR B, $eval("hexToB(\"{#COLOR Hex}\");"), "Global")
}
 

 

What am I doing wrong?

Link to post
Share on other sites

The code is just OK (http://screencast.com/t/XGWjyFGuhp), so no need to change it before you test it....actually I would give you an advice...save the code while it's working, so you can fall back when it stops....

 

However, use the exact code that I've used, but before starting it make sure that JavaScript or JQuery is loaded in browser...so just navigate to Google for example before you do that.

  • Like 1
Link to post
Share on other sites

The code is just OK (http://screencast.com/t/XGWjyFGuhp), so no need to change it before you test it....actually I would give you an advice...save the code while it's working, so you can fall back when it stops....

 

However, use the exact code that I've used, but before starting it make sure that JavaScript or JQuery is loaded in browser...so just navigate to Google for example before you do that.

 

Ahhh.  That worked, I ran all that code in a 'new browser window' and it freakin worked!  Thanks man!

 

I'm thinkin I may not even need to navigate anywhere because javascript is always enabled in the uihtml panel, probably just not enabled until you compile the bot (I as testing the node in ubot, which is probably why I had to navigate to make the functions work)

 

Thanks again I appreciate the help.

 

Adam.

Link to post
Share on other sites

FYI, UBot doesn't load JavaScript library (not even in compiled version), neither you can use the one from UI, since "run javascript" and "$eval" are executed inside the active browser...

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...