I wish for...

Make games! Discuss those games here.

Moderators: Bob the Hamster, marionline, SDHawk

Post Reply
User avatar
Master K
King Slime
Posts: 1899
Joined: Sat Jun 11, 2011 9:40 pm
Location: A windswept rock in the Atlantic Ocean

I wish for...

Post by Master K »

...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: Select all

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: Select all

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.
User avatar
charbile
Metal Slime
Posts: 601
Joined: Tue Jun 21, 2011 6:18 am

Post by charbile »

Random is its own function, so every instance needs to look like this:

Code: Select all

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: Select all

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.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

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: Select all

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 
User avatar
Master K
King Slime
Posts: 1899
Joined: Sat Jun 11, 2011 9:40 pm
Location: A windswept rock in the Atlantic Ocean

Post by Master K »

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.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

I am guessing that the part you are confused about is the if/then/else stuff?

Code: Select all

   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: Select all

   if (condition) then(
     action
   )else(
     alternative
   )
We could simplify that even further, and write it like this:

Code: Select all

   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: Select all

   # Don't do it this way unless you love confusion! ;)
   if (condition) then, begin
     action
   end, else, begin
     alternative
   end
User avatar
Master K
King Slime
Posts: 1899
Joined: Sat Jun 11, 2011 9:40 pm
Location: A windswept rock in the Atlantic Ocean

Post by Master K »

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: Select all

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
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

All the single-line if/then statements like this are wrong:

Code: Select all

   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: Select all

   if(wealth == 1) then(get money(5)) 
Last edited by Bob the Hamster on Mon Aug 15, 2011 8:46 pm, edited 1 time in total.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Also, this is wrong:

Code: Select all

set variable(stat(random,1,9) 
It should be

Code: Select all

stat := random(1,9)
(If you INSIST on using setvariable, you would write "set variable (stat, random(1,9))" )
Post Reply