Howdy, Stranger!

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

Can't I change a variable from inside a widget? Sugarcube 2.x

Hello. I have been working on a very basic combat system which is sort of widget-based (javascript doesn't like me and I don't like javascript) SO inside a widget name "EnemyTurn" I try to change both the round and the mc health, but it doesn't seem to be working. Is it impossible or am I just doing something wrong?

Comments

  • You're going to need to show what you're doing. We cannot help you if you don't give us details to work with.
  • edited February 2017
    Sounds like a problem I just had and it got answered by TheMadExile.
    @giucorreias :
    javascript doesn't like me and I don't like javascript
    Hehe, It's quite the opposite in my case. Please provide us your <<widget>> source, otherwise this can't be correctly answered.
  • I actually managed to fix it on my own!
    I was trying to update the variable's value without calling the passage again (that would be bad because I use append to give the player a battle log and calling the passage again would erase it). I solved it by using <<replace>>.
    Still! Thank you for the answers. Sorry to have bothered you all~
  • In case anyone is wondering, this is what I'm working with (still very much incomplete):
    <<widget "EndBattle">>
    	<<if $char.health gt $combatEnemy.health>>
    		<<append "#main-fight">><br>You have won!<</append>>
    		<<set $char.health to ($char.health - $lostHP)>>
    				<<replace "#char-health">>$char.health<</replace>>
    	<<else>>
    		<<append "#main-fight">><br>You have lost!<</append>>
    		<<set $char.health to ($char.health - $lostHP)>>
    				<<replace "#char-health">>$char.health<</replace>>
    	<</if>>
    <</widget>>
    
    <<widget "EnemyTurn">>
    	<<set $enemy_pts to (random(1, 20) + $combatEnemy.attack)>>
    	<<set $combatRound to ($combatRound + 1)>>
    	<<if $evade>>
    		<<if $enemy_pts gte $e_pts>>
    			<<set $lostHP to random(1, $enemyWeapon.damage)>>
    			<<if $lostHP gte $char.health>>
    				<<EndBattle>>
    			<<else>> 
    				<<append "#main-fight">><br>You have been hit! You lost $lostHP HP. It is now round $combatRound.<</append>>
    				<<replace "#combat-round">>$combatRound<</replace>>
    				<<set $char.health to ($char.health - $lostHP)>>
    				<<replace "#char-health">>$char.health<</replace>>
    			<</if>>
    		<<else>>
    			<<append "#main-fight">><br>You have successfully evaded! It is now round $combatRound.<</append>>
    			<<replace "#combat-round">>$combatRound<</replace>>
    		<</if>>
    	<</if>>
    <</widget>>
    
    <<widget "Evade">>
    	<<set $evade to true>>
    	<<if $eqArmour.armourtype eq "light">>
    		<<set $e_pts to (random(1, 20) + $athl.mod + testGameMod($att.dex))>>
    		<<EnemyTurn>>
    	<</if>>
    	<<if $eqArmour.armourtype eq "medium">>
    		<<if testGameMod($att.dex) gte 2>>
    			<<set $e_pts to (random(1, 20) + $athl.mod + 2>>
    			<<EnemyTurn>>
    		<<elseif testGameMod($att.dex) lt 2>>
    			<<EnemyTurn>>
    		<</if>>
    	<</if>>
    	<<if $eqArmour.armourtype eq "heavy">>
    		<<set $e_pts to (random(1, 20) + $athl.mod>>
    		<<EnemyTurn>>
    	<</if>>
    <</widget>>
    
Sign In or Register to comment.