Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

use img to set a variable not link to a passage?

Hi All,
I'm using sugarcane and have set up a minigame within my main game where I want to use image buttons  for actions.
So I've created a heap of buttons (.png) that have text such as attack, defend, flee written on them
I want the player to be able to click on the button and then I will report the action, such as if you click attack it says you swing your mighty sword at the monster.
The problem I seem to have is that if you use the img command it links to a passage what I want to do is not link to a passage but set a variable and stay on the same passage.
I was sure I managed to do this when I was playing around but now cannot get it to work can anyone please help?
Thanks
nowherecity24

Comments

  • Sugarcane does not support setting $variables within img links like SugarCube does nor does it have the equivalent of SugarCubes' click macro.

    So you can either implement something like either of the above two features using javascript or you can do something simple like the following:
    note: following assumes you have imported two images (attack_button and defend_button)

    :: StoryInit
    <<set $action to "none">>

    :: Start
    <<display "Actions">>

    :: Attack
    <<set $action to "attack">>\
    <<display "Actions">>

    :: Defend
    <<set $action to "defend">>\
    <<display "Actions">>

    :: Actions
    <<if $action neq "none">>\
    <<print "Your last action was: " + $action>>
    <<set $action to "none">>\
    <<endif>>\

    Select one of the two following actions:
    [img[attack_button][Attack]]
    [img[defend_button][Defend]]
    By using a Passage to represent each of your actions you can set your variable(s) as needed before re-displaying the actual passage that shows those buttons to the user.

    Another option would be to use the SugarCube story format and its version of the img link and something like the following:

    :: StoryInit
    <<set $action to "none">>

    :: Start
    <<display "Actions">>

    :: Actions
    <<if $action neq "none">>\
    <<print "Your last action was: " + $action>>
    <<set $action to "none">>\
    <<endif>>\

    Select one of the two following actions:
    [img[attack_button][Actions][$action = "attack"]]
    [img[defend_button][Actions][$action = "defend"]]
  • Hi greyelf,
    Thanks for your solutions -as you see in other post I did it a different way but I might try your way to see if it looks better.
    I should probably change to sugarcube as it seems more flexible and you and TheMadeExile offer good support but I have a stylesheet set up in sugarcane that I like and I've not been able to replicate it in sugarcube due to my limited ability.
    Cheers nowherecity24
  • Which story format you use is totally up to you but if you need help converting your CSS over from one format to another people here will help you.
Sign In or Register to comment.