0 votes
by (220 points)
edited by
Hi, the title says it all pretty much...

<h1><strong>Cheats</strong></h1>

<<textbox "_rawCodes" "">>
<<button "Continue" "Cheats">>
    <<set _rawCodes to _rawCodes.trim(ihealth)>>
    <<if _rawCodes isnot "">>
        <<set $Codes to _rawCodes>>
    <</if>>
<</button>>

<<if $Codes.includes("ihealth")>>
    <<set $hp to "$hp + 100">>
    <<set $maxhp to "maxhp + 100
<</if>>

<<if $Codes.includes("imana")>>
    <<set $mp to "mp + 100">>
    <<set $maxmp to "maxmp + 100">>
<</if>>

<<if $Codes.includes("lvlup")>>
    <<set $lvl to "$lvl + 1">>
    <<set $str to "$str + 5">>
    <<set $fort to "$fort + 5">>
    <<set $cons to "$cons + 5">>
    <<set $dex to "$dex + 5">>
    <<set $int to "$int + 5">>
    <<set $cha to "$cha + 5">>
    <<set $lbt to "$lbt + 5">>
<</if>>

Edit: i keep getting an error message whenever i enter any cheats in the txt box and click continue

1 Answer

0 votes
by (68.6k points)
edited by

There are many issues with that code.

  1. You're passing the <String>.trim() method a parameter, when it does not accept one, and the identifier you're passing, ihealth, probably does not exist anyway.
  2. You're not calling <String>.toLowerCase() when you probably need to, since you're testing against all lowercased strings.
  3. You're wrapping quotes around the right-hand side of the assignment expressions within the <<set>> macros, which you should not be doing.
  4. You're missing the closing angle brackets on the <<set>> for $maxhp.
  5. Assuming that is the Cheats passage you'll likely want to zero $Codes at the bottom of the passage or at the top of the <<button>>.  Otherwise, if the player enters nothing, the previous value will be rechecked.

For example:

!Cheats
<<textbox "_rawCodes" "">>
<<button "Continue" "Cheats">>
	<<set $Codes to "">>
	<<set _rawCodes to _rawCodes.trim().toLowerCase()>>
	<<if _rawCodes isnot "">>
		<<set $Codes to _rawCodes>>
	<</if>>
<</button>>

<<if $Codes.includes("ihealth")>>
	<<set $hp to $hp + 100>>
	<<set $maxhp to maxhp + 100>>
<</if>>

<<if $Codes.includes("imana")>>
	<<set $mp to mp + 100>>
	<<set $maxmp to maxmp + 100>>
<</if>>

<<if $Codes.includes("lvlup")>>
	<<set $lvl to $lvl + 1>>
	<<set $str to $str + 5>>
	<<set $fort to $fort + 5>>
	<<set $cons to $cons + 5>>
	<<set $dex to $dex + 5>>
	<<set $int to $int + 5>>
	<<set $cha to $cha + 5>>
	<<set $lbt to $lbt + 5>>
<</if>>

 

That said, unless you need the codes to persist beyond that passage, I'd suggest rewriting it to remove the need for the $Codes story variable.  For example:

!Cheats
<<textbox "_rawCodes" "">>
<<button "Continue" "Cheats">>
	<<set _rawCodes to _rawCodes.trim().toLowerCase()>>

	<<if _rawCodes.includes("ihealth")>>
		<<set $hp += 100>>
		<<set $maxhp += 100>>
	<</if>>

	<<if _rawCodes.includes("imana")>>
		<<set $mp += 100>>
		<<set $maxmp += 100>>
	<</if>>

	<<if _rawCodes.includes("lvlup")>>
		<<set $lvl += 1>>
		<<set $str += 5>>
		<<set $fort += 5>>
		<<set $cons += 5>>
		<<set $dex += 5>>
		<<set $int += 5>>
		<<set $cha += 5>>
		<<set $lbt += 5>>
	<</if>>
<</button>>

NOTES:

  1. You don't really need to the call to <String>.trim() in this version, since it does not test for the empty string; the <String>.includes() calls don't need it either as they perform substring matching.  Leaving it in doesn't hurt anything though.
  2. If that is the Cheats passage, then you probably do not need the <<button>> to also navigate to that passage again, so you could drop that argument.
  3. I replaced the var to var + value expressions with var += value, since it's less error prone; as you're only typing the variable name once.
...