Post new topic    
King Slime
Send private message
I wish for... 
 PostFri Aug 12, 2011 3:40 am
Send private message Reply with quote
...help with this script. This script is to be used with a wishing well, just so you understand my punny title.
The script won't compile. It says that powerwish might have an extra begin or (.

Now, brace yourself. Here is the entire script. I shall break it up into two parts: The wish selection, and the wish granting script.

Code:
plotscript, wishing well wealth, begin
   variable(wish)
   set variable(wish,random,1,50)
   
   if (wish == 50) then wealth wish
   else
   show text box(37)
   wait for text box
   end

plotscript, wishing well item, begin
   variable(wish)
   set variable(wish,random,1,50)
   
   if (wish == 50) then item wish
   else
   show text box(37)
   wait for text box
   end
   
plotscript, wishing well power, begin
   variable(wish)
   set variable(wish,random,1,50)
   
   if (wish == 50) then power wish
   else
   show text box(37)
   wait for text box
   end   
   
plotscript, wishing well health, begin
   variable(wish)
   set variable(wish,random,1,50)
   
   if (wish == 50) then health wish
   else
   show text box(37)
   wait for text box
   end
   
plotscript, wishing well skill, begin
   variable(wish)
   set variable(wish,random,1,50)
   
   if (wish == 50) then skill wish
   else
   show text box(37)
   wait for text box
   end

Code:
plotscript, wealth wish, begin
   variable(wealth)
   set variable(wealth,random,1,15)
   
   if(wealth == 1) then get money(5)
   if(wealth == 2) then get money(15)
   if(wealth == 3) then get money(25)
   if(wealth == 4) then get money(50)
   if(wealth == 5) then get money(100)
   if(wealth == 6) then get money(150)
   if(wealth == 7) then get money(250)
   if(wealth == 8) then get money(500)
   if(wealth == 9) then get money(750)
   if(wealth == 10) then get money(1000)
   if(wealth == 11) then get money(1200)
   if(wealth == 12) then get money(1400)
   if(wealth == 13) then get money(1600)
   if(wealth == 14) then get money(1800)
   if(wealth == 15) then get money(2000)
   play sound(6,false)
        wait(25)
   show text box(42)
   wait for text box
   end
   
plotscript, skill wish, begin
   variable(skill)
   variable(hero)
   set variable(skill,random,1,10)
   hero:= hero by slot(0)
   
   if(skill == 1) then teach spell(hero,atk:Falling)
   if(skill == 2) then teach spell(hero,atk:Shooting)
   if(skill == 3) then teach spell(hero,atk:Luck Shot)
   if(skill == 4) then teach spell(hero,atk:Wish)
   if(skill == 5) then teach spell(hero,atk:Luck Heal)
   
   play sound(6,false)
   wait(25)
   
   if(skill == 1) then show text box(46)
   if(skill == 2) then show text box(47)
   if(skill == 3) then show text box(48)
   if(skill == 4) then show text box(49)
   if(skill == 5) then show text box(50)
   wait for text box
   end
   
plotscript, power wish, begin
   variable(stat)
   set variable(stat(random,1,9)
   
   if(stat == 1) then increase HP
   if(stat == 2) then increase MP
   if(stat == 3) then increase attack
   if(stat == 4) then increase defense
   if(stat == 5) then increase aim
   if(stat == 6) then increase dodge
   if(stat == 7) then increase magic
   if(stat == 8) then increase will power
   if(stat == 9) then increase luck
   play sound(6)
   wait(25)
   show text box(42)
   wait for text box
   end
   
plotscript, health wish, begin
   set hero stat(1,stat:hp, get hero stat(1,stat:Health,maximum stat), current stat)
        set hero stat(2,stat:hp, get hero stat(2,stat:Health,maximum stat), current stat)
        set hero stat(3,stat:hp, get hero stat(3,stat:Health,maximum stat), current stat)
        set hero stat(4,stat:hp, get hero stat(4,stat:Health,maximum stat), current stat)
   
   set hero stat(1,stat:Mana, get hero stat(1,stat:Health,maximum stat), current stat)
        set hero stat(2,stat:Mana, get hero stat(2,stat:Health,maximum stat), current stat)
        set hero stat(3,stat:Mana, get hero stat(3,stat:Health,maximum stat), current stat)
        set hero stat(4,stat:Mana, get hero stat(4,stat:Health,maximum stat), current stat)
   play sound(6,false)
   wait(25)
   show text box(44)
   wait for text box
   end


I left out the item wish giving script because i'm gonna wait until later, when I have more items created. Also, feel free to clean up any other errors if you spot them.
Metal Slime
Send private message
 
 PostFri Aug 12, 2011 12:45 pm
Send private message Reply with quote
Random is its own function, so every instance needs to look like this:

Code:

set variable(wish,random(1,50))


Functions within functions. We must go deeper. This is a purely cosmetic preference in most ways, but instead of long if/then chains, I prefer the switch statement. Take a look, replacing "wealth wish":

Code:

plotscript, wealth wish, begin
   variable(wealth)
   set variable(wealth,random,1,15)

   switch (wealth) do
   (
      case (1) do (get money(5))
      case (2) do (get money(15))
      case (3) do (get money(25))
      #etc
   )
   play sound(6,false)
   while (sound is playing(6)) do(wait(1))
   show text box(42)
   wait for text box
   end


I also changed the "wait(25)" into waiting for the sound to finish playing instead.
Liquid Metal King Slime
Send private message
 
 PostFri Aug 12, 2011 4:35 pm
Send private message Reply with quote
When trying to decipher hspeak's unfortunately confusing error messages, remember that ( means exactly the same thing as "begin" and ) means exactly the same thing as "end"

All of your "wishing well" have messed up "if" commands.

Also, although the "set variable" command does still work for backwards compatibility, it has been deprecated for years. You should use := to store a value in a variable (where did you even find the "set variable command"? I thought I had deleted all references to it from the documentation and examples)

Here is how it should be.

Code:

plotscript, wishing well wealth, begin
   variable(wish)
   wish := random(1, 50)
   
   if (wish == 50) then(
     wealth wish
   )else(
     show text box(37)
     wait for text box
   )
end
King Slime
Send private message
 
 PostFri Aug 12, 2011 10:28 pm
Send private message Reply with quote
Thank you. But now, how can I apply it to the script? It sorta confuses me, because I don't know how it should all go. The scripts are unique and the same in the same sense.
Liquid Metal King Slime
Send private message
 
 PostFri Aug 12, 2011 10:38 pm
Send private message Reply with quote
I am guessing that the part you are confused about is the if/then/else stuff?

Code:

   if (wish == 50) then(
     wealth wish
   )else(
     show text box(37)
     wait for text box
   )


Here is a more simplified form of the same thing

Code:

   if (condition) then(
     action
   )else(
     alternative
   )


We could simplify that even further, and write it like this:

Code:

   if (condition) then(action) else(alternative)


Sometimes you might see example scripts that use "then, begin" instead of "then(" but they mean exactly the same thing. The following example works the same way, but I don't recommend it, since it is kinda ugly (and involves more pointless typing, and requires confusing commas)

Code:

   # Don't do it this way unless you love confusion! ;)
   if (condition) then, begin
     action
   end, else, begin
     alternative
   end
King Slime
Send private message
 
 PostMon Aug 15, 2011 7:44 pm
Send private message Reply with quote
Still saying the powerwish might have an extra begin or (.
Heres the edited script. The stat raises and the item wish is not added.

Code:
plotscript, wishing well wealth, begin
   variable(wish)
   set variable(wish,random(1,50))
   
   if (wish == 50) then(
     wealth wish
   )else(
     show text box(37)
     wait for text box
   )
     end

plotscript, wishing well item, begin
   variable(wish)
   set variable(wish,random(1,50))
   
   if (wish == 50) then(
     item wish
   )else(
     show text box(37)
     wait for text box
   )
   end
   
plotscript, wishing well power, begin
   variable(wish)
   set variable(wish,random(1,50))
   
if (wish == 50) then(
     power wish
   )else(
     show text box(37)
     wait for text box
   )
   end   
   
plotscript, wishing well health, begin
   variable(wish)
   set variable(wish,random,1,25)
   
   if (wish == 25) then(
     health wish
   )else(
     show text box(37)
     wait for text box
   )
   end
   
plotscript, wishing well skill, begin
   variable(wish)
   set variable(wish,random,1,50)
   
   if (wish == 50) then(
     skill wish
   )else(
     show text box(37)
     wait for text box
   )
   end
   
plotscript, wealth wish, begin
   variable(wealth)
   set variable(wealth,random,1,15)
   
   if(wealth == 1) then get money(5)
   if(wealth == 2) then get money(15)
   if(wealth == 3) then get money(25)
   if(wealth == 4) then get money(50)
   if(wealth == 5) then get money(100)
   if(wealth == 6) then get money(150)
   if(wealth == 7) then get money(250)
   if(wealth == 8) then get money(500)
   if(wealth == 9) then get money(750)
   if(wealth == 10) then get money(1000)
   if(wealth == 11) then get money(1200)
   if(wealth == 12) then get money(1400)
   if(wealth == 13) then get money(1600)
   if(wealth == 14) then get money(1800)
   if(wealth == 15) then get money(2000)
   play sound(6,false)
        while (sound is playing(6)) do(wait(1))
   show text box(42)
   wait for text box
   end
   
plotscript, skill wish, begin
   variable(skill)
   variable(hero)
   set variable(skill,random,1,5)
   hero:= hero by slot(0)
   
   if(skill == 1) then teach spell(hero,atk:Falling)
   if(skill == 2) then teach spell(hero,atk:Shooting)
   if(skill == 3) then teach spell(hero,atk:Luck Shot)
   if(skill == 4) then teach spell(hero,atk:Wish)
   if(skill == 5) then teach spell(hero,atk:Luck Heal)
   
   play sound(6,false)
   while (sound is playing(6)) do(wait(1))
   
   if(skill == 1) then show text box(46)
   if(skill == 2) then show text box(47)
   if(skill == 3) then show text box(48)
   if(skill == 4) then show text box(49)
   if(skill == 5) then show text box(50)
   wait for text box
   end
   
plotscript, power wish, begin
   variable(stat)
   set variable(stat(random,1,9)
   
   if(stat == 1) then increase HP
   if(stat == 2) then increase MP
   if(stat == 3) then increase attack
   if(stat == 4) then increase defense
   if(stat == 5) then increase aim
   if(stat == 6) then increase dodge
   if(stat == 7) then increase magic
   if(stat == 8) then increase will power
   if(stat == 9) then increase luck
   play sound(6)
   while (sound is playing(6)) do(wait(1))
   show text box(42)
   wait for text box
   end
   
plotscript, health wish, begin
   set hero stat(1,stat:hp, get hero stat(1,stat:Health,maximum stat), current stat)
        set hero stat(2,stat:hp, get hero stat(2,stat:Health,maximum stat), current stat)
        set hero stat(3,stat:hp, get hero stat(3,stat:Health,maximum stat), current stat)
        set hero stat(4,stat:hp, get hero stat(4,stat:Health,maximum stat), current stat)
   
   set hero stat(1,stat:Mana, get hero stat(1,stat:Mana,maximum stat), current stat)
        set hero stat(2,stat:Mana, get hero stat(2,stat:Mana,maximum stat), current stat)
        set hero stat(3,stat:Mana, get hero stat(3,stat:Mana,maximum stat), current stat)
        set hero stat(4,stat:Mana, get hero stat(4,stat:Mana,maximum stat), current stat)
   play sound(6,false)
   while (sound is playing(6)) do(wait(1))
   show text box(44)
   wait for text box
   end
Liquid Metal King Slime
Send private message
 
 PostMon Aug 15, 2011 8:45 pm
Send private message Reply with quote
All the single-line if/then statements like this are wrong:

Code:
   if(wealth == 1) then get money(5)


What the compiler sees is an "if" statement all by itself with no "then" at all. Right after that, it sees an unknown command "thengetmoney(5)"

Here is how you should write it:

Code:
   if(wealth == 1) then(get money(5))
Metal King Slime
Send private message
 
 PostTue Aug 16, 2011 10:35 am
Send private message Reply with quote
Also, this is wrong:
Code:
set variable(stat(random,1,9)

It should be
Code:
stat := random(1,9)

(If you INSIST on using setvariable, you would write "set variable (stat, random(1,9))" )
Display posts from previous: