Load images using javascript

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.

Comments

  • 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.
  • 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?
  • 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.
  • Not sure if jscript has an RGB function specifically. So try:
    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.
  • 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...
  • The button source should say
    a();
    
    not just
    a
    

    Try the attached character sheet definition
  • 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?
  • I think you just have a small logic error in the piece that controls the color.

    You have something like
    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.
  • 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.
  • Is it possible to declare a variable in the button source?
    **update** Apparently it is.. Now if I can figure out how to use one function instead of many functions for the same thing, I'd be laughing!
    **new character file attached if anyone can give me a hand up!
  • I TOTALLY GOT IT!! :D
    Sweet. Now I feel smart again... I'll try not letting this go to my head.
    And yes, it's ok to laugh at me. To me, this is a big deal...
    I hope to have a complete Character Sheet by the end of next week!
    The new test is attached.
  • Alright, I'm back.
    I got my sheet set up and it looks pretty good. A few tweaks here and there yet, but all-in-all it works..
    However, I can't seem to get some information to save with the file, so if anyone knows the problem with this, please let me know.
    I need each box that cycles through different colors to be saved, so the player doesn't have to re-set the boxes each time they open the file.

    thanks
  • You cant save extra info like that. What you want to do is create an OnOpen event and set the colors there when the file is loaded.
  • Hi,
    I know I said I would post my character sheet a long time ago, but life has been good.
    So here it is, attached. It's still not complete because I haven't figured out the save feature yet.
    The problem is that after using the sheet, setting the damages and modifiers, then after the session is done and I save the character, none of the damage boxes remain checked, but the attributes don't reset either. So the next time we open the character sheet, the stats are modified, but the damage boxes are not checked, resulting in further modified stats, instead of starting where we left off from a previous session.

    I know that doesn't make a lot of sense, but try the sheet to get a feel for what I'm talking about.
  • Thats a really great sheet!

    Are you saying the check boxes arent saving between uses?
  • Yes, the damage boxes are not saving between uses, but the stats remain at the modified rating, so the next time you open your character and he takes more damage, the stats go down even further.

    Any help with this is appreciated. Thanks
  • Hmm - they seem to be saving & loading for me. You're talking about the damage check boxes on the body, right? (the rectangles that change color)
  • Yes, those damage boxes. They don't show up with color in them when I reload after closing the character sheet.. Could it be my version of java? I'll have to see if I am up to date.
  • I just tried it again, same thing. I open the character in the viewer and give him a few knocks to the head. Then I save it, and close the viewer. When I open the file again in the viewer, the modifiers are there, but the colored wound boxes are reset to white. They need to have the damages already applied, like when I saved it...

    What would be the difference between your viewer and mine?
  • Still can't get them to save properly. What did you do differently? What version of Java/Javascript do you have? There's got to be an answer here some where... Eesh...
  • What version of the viewer are you using? Do you have 1.01c?
  • Yup.
    I'm using 1.01c
  • Have you tried debugging by putting MsgBox() funcs in the code to see if the functions to set the colors are being run?
  • I would love to, but I really don't know how. I'm not a programmer. I am stumbling trying to figure this out to begin with.
    I thought my code was pretty straight forward, but obviously I don't understand programming. I'm starting to think it's evil! :twisted:
    I'll upload my latest, but it's not like I changed anything cause I don't have a clue. This is getting beyond me.

    I open the sheet in the designer.. I test the sheet in the viewer.. I add some damage to the figure, resulting in a change in his stats.. I save the sheet in the viewer.. I push the open button.. The sheet loads in the view.. The damaged stats are still there, but the boxes are reset to white again. The boxes need to retain their color so as to add/subtract the damage from the figure.

    Why is this not working?
  • I'm not sure whats going on - I just tested it in an empty VM and it worked fine out of the box.

    I downloaded the same char sheet designer thats online and installed it.
    Opened the definition file with the designer.
    Did 'test in viewer'.
    Clicked one of the damage boxes until it changed to red (the boxes on the first tab over the image of a person)
    Saved the file.
    Quit the viewer.
    Double clicked the .character I just made in Windows Explorer.
    The sheet opened up, and the box was red as before

    I repeated the process several times, changing other boxes, and it always works.

Leave a Comment