Load images using javascript

For discussion about the NBOS Character Sheet Designer and Viewer.

Load images using javascript

Postby Naythan » Fri Mar 18, 2011 10:02 pm

I'm more of a graphic design persone, not a programmer, but sometimes I can figure it out.

Is it possible to load an image into the character designer using javascript?
I have a series of "checkboxes" that need to cycle through 3 different images (blank,/,X).
I guess I could represent these three choices by creating a box that changes colors instead, (white/grey/black), but I would prefer the images idea.

Is this possible?
thanks in advance.
Image
Naythan
Torch Bearer
 
Posts: 17
Joined: Fri Mar 18, 2011 9:57 pm
Location: Canada

Re: Load images using javascript

Postby Ed_NBOS » Sat Mar 19, 2011 11:33 pm

You cant load an image, but if you put the images you want to use on the character sheet, you should be able to toggle their visibility as you need them.
Ed_NBOS
Site Admin
 
Posts: 522
Joined: Wed Jul 08, 2009 12:16 am

Re: Load images using javascript

Postby Naythan » Sun Mar 20, 2011 2:42 pm

ok, can I have a box that changes colors each time it is pressed. Go from White to grey, grey to black, and black to white again?
Image
Naythan
Torch Bearer
 
Posts: 17
Joined: Fri Mar 18, 2011 9:57 pm
Location: Canada

Re: Load images using javascript

Postby Naythan » Fri Mar 25, 2011 8:49 pm

ok, I've been trying forever to get something to work.
I have a button, called button1
I have a square that is filled with the color red, rgb(255,0,0).

Here's my simple little javascript, written in the script window.

// declare colors
var Blue = rgb(0,128,255)
var Grey = rgb(192,192,192)
var Black = rgb(0,0,0)
var White = rgb(255,255,255)
var Red = rgb(255,0,0)

function clickme {
box1.FillColor=Grey
}

In button1, the source is clickme, which should run the script above.
The script should take box1, and change it's color to rgb(255,255,0)

Is this correct? Or what am I doing wrong?
Any help would be great, thanks.
Image
Naythan
Torch Bearer
 
Posts: 17
Joined: Fri Mar 18, 2011 9:57 pm
Location: Canada

Re: Load images using javascript

Postby Ed_NBOS » Fri Mar 25, 2011 11:01 pm

Not sure if jscript has an RGB function specifically. So try:

Code: Select all
function a()  //the source for a button
{
   Box1.FillColor = rgb( 255, 0, 0);
}

function rgb( r, g, b)
{
    return r + (256 * g) + (65536 * b);
}


This works for me on a test sheet.

Also, makes sure your object is not set to clear.
Ed_NBOS
Site Admin
 
Posts: 522
Joined: Wed Jul 08, 2009 12:16 am

Re: Load images using javascript

Postby Naythan » Sat Mar 26, 2011 11:31 am

This isn't working for me.
I downloaded the latest version of Character Designer.
I started a new sheet with only one button and one red box.
I named the box Box1, and the button source says a
I copied your script into the script sheet.

Nothing, the box stays as a red box...

However if I put Box1.FillColor=(0,255,0) into the buttons source, it turns black, but I can't make it turn the color I want, green in this case...
Naythan
Torch Bearer
 
Posts: 17
Joined: Fri Mar 18, 2011 9:57 pm
Location: Canada

Re: Load images using javascript

Postby Ed_NBOS » Wed Mar 30, 2011 12:49 am

The button source should say
Code: Select all
a();
not just
Code: Select all
a


Try the attached character sheet definition
Attachments
color.csd
(756 Bytes) Downloaded 88 times
Ed_NBOS
Site Admin
 
Posts: 522
Joined: Wed Jul 08, 2009 12:16 am

Re: Load images using javascript

Postby Naythan » Wed Mar 30, 2011 11:06 am

ok, that worked.
I've attached a character sheet of what I'm looking for.
I need to create 3 different wound levels represented by colors. Blue/Grey/Black. Each starts out as Blue.
There will be 3 different catagories that the player needs to be able to change. Physical/Mental/Spiritual
Each Catagory has 3 "chances" (boxes) that can be changed... Is this complicated to do?
I don't suppose a colored box can be changed to a button? Or a button have different color backgrounds? Or maybe a Checkbox color that can change?
But each time the box is clicked, the current color changes to the next color...

Perhaps it's possible to get the 3 FillColor from Boxes hidden on another page, and write them to the Box.FillColor?
Attachments
temp01.csd
(5.34 KiB) Downloaded 87 times
Image
Naythan
Torch Bearer
 
Posts: 17
Joined: Fri Mar 18, 2011 9:57 pm
Location: Canada

Re: Load images using javascript

Postby Ed_NBOS » Mon Apr 04, 2011 4:34 pm

I think you just have a small logic error in the piece that controls the color.

You have something like
Code: Select all
if (a = 1)
    a = 2;
if (a = 2)
   a = 3;

Which always results in 3. Use a switch statement, or if ... else should take care of the problem.
Ed_NBOS
Site Admin
 
Posts: 522
Joined: Wed Jul 08, 2009 12:16 am

Re: Load images using javascript

Postby Naythan » Mon Apr 04, 2011 8:29 pm

Ok, that's working.
So now I need many of these button/square combinations.
Click button1 changes the fill in box1
Click button2 changes the fill in box2.. ect.
Is there a better way to do this than copying the same code for every button/square? There will be 100 squares on 1 character sheet.

I was thinking of an array, but I don't know how to use it yet. This will be my project for this week.
**I've been trying to figure this out, but still it's not working**
Even making copies of the button and changing the variable names doesn't want to work. I thought that would be the simple way of doing it...

Thank you ever so much Ed for your help. I will post my finished sheet when it's complete for anyone else that wants to take a look at it. For now, I'm posting my test sheet.
Attachments
temp02.csd
(2.51 KiB) Downloaded 91 times
Image
Naythan
Torch Bearer
 
Posts: 17
Joined: Fri Mar 18, 2011 9:57 pm
Location: Canada

Next

Return to Character Sheet Designer General

Who is online

Users browsing this forum: No registered users and 1 guest

cron