Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

Something strange in the script
Goto page 1, 2, 3, 4  Next
 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
bis_senchi




Joined: 08 Jun 2004
Posts: 460
Location: Reims, France

PostPosted: Thu Apr 27, 2006 6:44 am    Post subject: Something strange in the script Reply with quote

Could somoene tell me if he/or she sees something strange in this script?

Code:

script, my keyboard getquick, begin

getquicky:=true
while (getquicky) do, begin
suspend Npcs
suspend player

if (running==false), then, begin

if (herodirection(me)==right ,and, hero is walking(me) == false), then, begin
running:=true
set hero speed (me, 10),
walk hero (me, east, 2),
set hero speed (me, 4),
wait for hero (me),
wait (3))
else, begin

if (herodirection(me)==left ,and, hero is walking(me) == false), then, begin
running:=true
set hero speed (me, 10),
walk hero (me, west, 2),
set hero speed (me, 4),
wait for hero (me),
wait (3))
else, begin

if (herodirection(me)==up, and, hero is walking(me) == false),then, begin
running:=true
set hero speed (me, 10),
walk hero (me, north, 2),
set hero speed (me, 4),
wait for hero (me),
wait (3))
else, begin

if (herodirection(me)==down, and, hero is walking(me) == false), then, begin
running:=true
set hero speed (me, 10),
walk hero (me, south, 2),
set hero speed (me, 4),
wait for hero (me),
wait (3)
running:=false)
))

getquicky:=false
wait(1)
end #end of if running
end #end of the if check tag
end #end of the while loop key
resume Npcs
resume player
end #end of the plotscript
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
msw188




Joined: 02 Jul 2003
Posts: 1041

PostPosted: Thu Apr 27, 2006 7:57 am    Post subject: Reply with quote

1. You may need a comma after the end parenthesis in the 'while' line near the top.

2. Right now, the variable 'running' is set to false INSIDE the if block for moving down. Thus, if the person is facing any direction other than south, 'running' remains true, even after the script terminates.

3. Why does the variable 'getquicky' exist? Right now the while loop runs once, and that's it, no matter what happens. Furthermore, while this script is being run, no other script can be running to reference this variable.

4. What is the end doing that is commented as "end of the if check tag"?
Back to top
View user's profile Send private message Visit poster's website
Mike Caron
Technomancer




Joined: 26 Jul 2003
Posts: 889
Location: Why do you keep asking?

PostPosted: Thu Apr 27, 2006 1:15 pm    Post subject: Reply with quote

I cleaned this up for you. Please please please, in the future, use indentation! It will save you a lot of grief! It will help you spot errors!

Further, either use begin and end, or ( and ). If you use both, it gets really confusing. And, if you use ( and ), don't do something liket this:

Code:
wait(1)) #note the extra ) which closes this block


Anyway, my comments on the code itself are below.

Code:
script, my keyboard getquick, begin
   getquicky:=true #where is this defined?
   while (getquicky) do, begin
      suspend Npcs
      suspend player
      if (running==false), then, begin
         if (herodirection(me)==right, and, hero is walking(me) == false) then, begin
            running:=true
            set hero speed (me, 10)
            walk hero (me, east, 2)
            set hero speed (me, 4)
            wait for hero (me)
            wait (3)
         end, else, begin
            if (herodirection(me)==left ,and, hero is walking(me) == false) then, begin
               running:=true
               set hero speed (me, 10)
               walk hero (me, west, 2)
               set hero speed (me, 4)
               wait for hero (me)
               wait (3)
            end, else, begin
               if (herodirection(me)==up, and, hero is walking(me) == false) then, begin
                  running:=true
                  set hero speed (me, 10)
                  walk hero (me, north, 2)
                  set hero speed (me, 4)
                  wait for hero (me)
                  wait (3)
               end, else, begin
                  if (herodirection(me)==down, and, hero is walking(me) == false) then, begin
                     running:=true
                     set hero speed (me, 10)
                     walk hero (me, south, 2)
                     set hero speed (me, 4)
                     wait for hero (me)
                     wait (3)
                     running:=false
                  end
               end
            end
            getquicky:=false
            wait(1)
         end #end of if running
      end #end of the if check tag
   end #end of the while loop key
   resume Npcs
   resume player
end #end of the plotscript


Comments:

1. Code like this is wrong:

Code:
set hero speed (me, 10)
walk hero (me, south, 2)
set hero speed (me, 4)
wait for hero (me)


It won't move them 2 tiles at 10 px/tick, it will set their speed to 10, queue up their movement, and set their speed back to 4, making them move at 4 px/tick. This, however, is correct:

Code:
set hero speed (me, 10)
walk hero (me, south, 2)
wait for hero (me)
set hero speed (me, 4)


2. Why do you test "hero is walking (me) == false" in every block? Wouldn't it do the same thing to move that to the "if(running == false)" bit?

3. "getquicky:=false" is inside the else of the "if (hero direction(me) == right)" block, which may not be where you want it, as it will only kill the loop if they're not moving right.

4. Why the loop anyway?

5. Why are suspend npcs/heroes inside the loop, while resume npcs/herores are outside the loop? Harmless, but odd.
_________________
I stand corrected. No rivers ran blood today. At least, none that were caused by us.

Final Fantasy Q
OHR Developer BLOG
Official OHRRPGCE Wiki and FAQ
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
bis_senchi




Joined: 08 Jun 2004
Posts: 460
Location: Reims, France

PostPosted: Fri Apr 28, 2006 11:09 pm    Post subject: The code works Thanks! .... but here's another one sorry! Reply with quote

The wode works now perfectly Razz Razz Thanks a million!
Here are the questions that msw188 have posted

Quote:

3. Why does the variable 'getquicky' exist? Right now the while loop runs once, and that's it, no matter what happens. Furthermore, while this script is being run, no other script can be running to reference this variable.

4. What is the end doing that is commented as "end of the if check tag"?


And here are the ones that Mike Caron have posted

Quote:


4. Why the loop anyway?

5. Why are suspend npcs/heroes inside the loop, while resume npcs/herores are outside the loop? Harmless, but odd.


I've decided to use an global variable because I thought it would prevent the script from beeing overloaded. But my problem was due to fact that my script was not an autonumber script. Now that I've implemented the line "define script (autonumber,my keyboard getquick,none) " I don't have any bugs !

I comment each end command to be sure there are no missing ends or begins. Anyway here's another "buggy script"

Code:

script,my keyboard pause, begin

  loopkey:=true
  while (loopkey) do, begin
   
  variable(d,h,m,s,) #days, hours, minutes, seconds
  suspend player
  suspend npcs
 
  show text box (334) #pause
  suspend box advance   
  d:= days of play
  h:= hours of play
  m:= minutes of play

  s:= read general (54) #ToDo: make an official seconds of play command       
  pauseisactive:=true
 
  while (pauseisactive) do, begin
  wait (1)
  if(key is pressed(key:numlock)) then, begin
  (pauseisactive:=false)
  wait (2)
  advance text box
  end #end of the if pressed
  end #end of the while pause is active

  write general(51, d) #ToDo: Make official set days of play, etc. commands
  write general(52, h)
  write general(53, m)
  write general(54, s)     
 
  resume player
  resume npcs   
  #all done
 
  loopkey:=false
  wait (1)

end #end of the while loop key
end #end of the plotscript



Anyways a huge thanks once more!
Could somoene explain me what is indentation and how to use it?
As for the other script any comments on bugs and any code improvements are welcomed!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Mike Caron
Technomancer




Joined: 26 Jul 2003
Posts: 889
Location: Why do you keep asking?

PostPosted: Sat Apr 29, 2006 8:13 am    Post subject: Re: The code works Thanks! .... but here's another one sorry Reply with quote

bis_senchi wrote:
I comment each end command to be sure there are no missing ends or begins. Anyway here's another "buggy script"


That's a good technique, but...

bis_senchi wrote:
Could somoene explain me what is indentation and how to use it?


Indentation is using white space to outline blocks. The rule is this: tab in once when you enter a block, tab out once when you leave a block. If you do it consistantly, and you're not all the way at the left by the end of the script, you've missed an end. Conversely, if you've tabbed out all the way, and you're not at the end of the script, then you have too many ends.

Some editors will remember your indentation level (mostly text editors designed for coding), making it easy to go TAB (to indent) or Shift-TAB (to outdent). I prefer Crimson Editor.

Any way, this script seems ok. I've cleaned and indented it again for you, but I don't see any obvious flaws (except that the nightly has proper seconds of play, and set ___ of play commands).

Code:
script,my keyboard pause, begin
   loopkey:=true
   while (loopkey) do, begin
      variable(d,h,m,s) #days, hours, minutes, seconds
      suspend player
      suspend npcs
      show text box (334) #pause
      suspend box advance
      d:= days of play
      h:= hours of play
      m:= minutes of play
      s:= read general (54) #ToDo: make an official seconds of play command
      pauseisactive:=true
      while (pauseisactive) do, begin
         wait (1)
         if(key is pressed(key:numlock)) then, begin
            pauseisactive:=false
            wait (2)
            advance text box
         end #end of the if pressed
      end #end of the while pause is active

      write general(51, d) #ToDo: Make official set days of play, etc. commands
      write general(52, h)
      write general(53, m)
      write general(54, s)

      resume player
      resume npcs
      #all done

      loopkey:=false
      wait (1)

   end #end of the while loop key
end #end of the plotscript


Although, now that I think about it, why do you use the While loop? loopkey is always set to false, so it always runs only once. There's no point to it, just like in your previous script.
_________________
I stand corrected. No rivers ran blood today. At least, none that were caused by us.

Final Fantasy Q
OHR Developer BLOG
Official OHRRPGCE Wiki and FAQ
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
msw188




Joined: 02 Jul 2003
Posts: 1041

PostPosted: Sat Apr 29, 2006 9:15 am    Post subject: Reply with quote

I always seem to get these commands confused, but wouldn't it be better to have a 'wait for key' in the second (should really be the first) while loop, rather than the initial wait(1)?

Also I'm wondering, what is 'read general' and 'write general'? They seem like they should be 'read global' and 'write global'.

How is this script buggy? What seems to be going wrong?
Back to top
View user's profile Send private message Visit poster's website
Mike Caron
Technomancer




Joined: 26 Jul 2003
Posts: 889
Location: Why do you keep asking?

PostPosted: Sat Apr 29, 2006 11:24 am    Post subject: Reply with quote

msw188 wrote:
I always seem to get these commands confused, but wouldn't it be better to have a 'wait for key' in the second (should really be the first) while loop, rather than the initial wait(1)?


No, not really. He's waiting in a tight loop for the player to press num lock, and so that's perfectly valid. The wait(1) is to not lock up the engine.

msw188 wrote:
Also I'm wondering, what is 'read general' and 'write general'? They seem like they should be 'read global' and 'write global'.


No, read/write general modify the crap in the GEN lump, which stores miscelaneous data, including the time of play.

msw188 wrote:
How is this script buggy? What seems to be going wrong?


Yes, that would be a good for us to know...
_________________
I stand corrected. No rivers ran blood today. At least, none that were caused by us.

Final Fantasy Q
OHR Developer BLOG
Official OHRRPGCE Wiki and FAQ
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
bis_senchi




Joined: 08 Jun 2004
Posts: 460
Location: Reims, France

PostPosted: Sun Apr 30, 2006 9:52 pm    Post subject: The problem is when I launch my script Reply with quote

Well my script is not really buggy . To tell the truth the problem is that I don't manage to end it correctly.

Here's what happen. When I press on numlock the following script
launch

Code:

script, customized keyboard, begin

if (key is pressed(key: numlock)) then, begin
my keyboard pause
end

which make launch "my keyboard pause" that you can read above. And when the script is launched and when I press a second time on pause/numlock the if (keyispressed(key:numlock))then, begin make starts all over from the beginning.

My problem is the following: the part of the script is effective only during a few seconds and then the text box with pause appears again.

Code:

 if(key is pressed(key:numlock)) then, begin
            pauseisactive:=false
            wait (2)
            advance text box
         end #end of the if pressed
      end #end of the while pause is active

      write general(51, d) #ToDo: Make official set days of play, etc. commands
      write general(52, h)
      write general(53, m)
      write general(54, s)

      resume player
      resume npcs
      #all done

      loopkey:=false
      wait (1)
 end #end of the while loop key
end #end of the plotscript
 


I think global variables would be useful here but I don't see how to combine them so that the script launch only once. May be I shall put a global variable before the script launch and make it stop after the while loop key...

So any suggestions to solve this problem?
Thanks very much in advance for the help provided.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
msw188




Joined: 02 Jul 2003
Posts: 1041

PostPosted: Mon May 01, 2006 6:06 am    Post subject: Reply with quote

Make sure that 'pauseisactive' is a global variable, and then have your custom keyboard script read:

if (key is pressed(key:numlock), and, (pauseisactive==false)), then
begin
my keyboard pause
end

However, if there are wait commands in your custom keyboard script, there might still be a problem, because that script is getting called when you push numlock and is thus interrupting the pausing script. If I were you, I would rearrange it and have a separate 'unpausing' script, and have the custom keyboard script go like this:

if (key is pressed(hey:numlock)), then
begin
if(pauseisactive==false),then
begin
my keyboard pause
end
else #thus, pauseisactive must be true
begin
my keyboard unpause
end
end

Then have 'my keyboard pause' merely suspend the player and the text box advancement (as well as recording the time settings), while 'my keyboard unpause' would resume those things, and reset the time stuff.

That is only a plan, I haven't tested it at all yet. If you need more specific help, just ask, and we'll be able to guide you through that.
Back to top
View user's profile Send private message Visit poster's website
bis_senchi




Joined: 08 Jun 2004
Posts: 460
Location: Reims, France

PostPosted: Sat May 06, 2006 3:43 am    Post subject: the code still needs some works Reply with quote

I've worked on my code and here are the new versions of the scripts

Code:


define script (autonumber,customized keyboard,none)
define script (autonumber,my keyboard unpaused,none)

  Global variable (6, loopkey)   
  Global variable (10, day)
  Global variable (11, hour)
  Global variable (12, minute)
  Global variable (13, savetime)

#-----------------------------------------------------------
script, customized keyboard, begin

loopkey:=true

while (loopkey) do, begin

if (key is pressed(key: z)) then, begin
my keyboard getquick
end
#Key is pressed z pour accelerer

if (key is pressed(key: numlock), and, (pauseisactive==false)), then, begin
my keyboard pause
end
#Key is pressed numlock pour faire pause
else, begin
#thus, pauseisactive must be true
my keyboard unpaused
end

if (key is pressed(key: r)) then, begin
my keyboard jump
end
#press R make jump the hero

loopkey:=false
wait (1) #wait 1 is very very important

end #end of the while (loop key) command

end #end of the plotscript
#-------------------------------------------------------------
script,my keyboard pause, begin

suspend player
suspend npcs

show text box (334) #pause
suspend box advance

day:= days of play
hour:= hours of play
minute:= minutes of play
savetime:= read general (54) #ToDo: make an official seconds of play command
pauseisactive:=true
wait(1)

resume box advance
resume player
resume npcs

end #end of the plotscript
#-------------------------------------------------------------
script, mykeyboard unpaused, begin

while (pauseisactive) do, begin
wait (1)
suspend box advance
suspend player
suspend npcs

advance text box

write general(51, day) #ToDo: Make official set days of play, etc. commands
write general(52, hour)
write general(53, minute)
write general(54, savetime)

resume box advance
resume player
resume npcs

pauseisactive:=false
wait(2)
end #end of the while pause is active

end #end of plotscript
#-------------------------------------------------------------


I am pleased to tell you that now my script unpaused but It works with whatever key I press (and I would like it to work only with key numlock)
As the variable are effective only in one script I had to change to store time commands. All suggestions to embetter the script are welcomed.

As always thanks very much for the help!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Mike Caron
Technomancer




Joined: 26 Jul 2003
Posts: 889
Location: Why do you keep asking?

PostPosted: Sun May 07, 2006 7:03 pm    Post subject: Reply with quote

Code:
if (key is pressed(key: numlock), and, (pauseisactive==false)), then, begin
my keyboard pause
end
#Key is pressed numlock pour faire pause
else, begin
#thus, pauseisactive must be true
my keyboard unpaused
end


I'd bet most of my worldly posessions that this code is the problem.

What it says now is:

If numlock is pressed and pauseisactive is false, then
my keyboard pause
otherwise, if numlock isn't pressed or pause is active is true, then
my keyboard unpause

So, it's unpausing whenever this script is run (coincidentally, when a key is pressed).

You need to change it like this:

Code:
if (key is pressed(key: numlock)) then, begin
  if (pauseisactive==false) then, begin
    #Key is pressed numlock pour faire pause
    my keyboard pause
  end, else, begin
    #thus, pauseisactive must be true
    my keyboard unpaused
  end
  #c'est bon, oui?
end

_________________
I stand corrected. No rivers ran blood today. At least, none that were caused by us.

Final Fantasy Q
OHR Developer BLOG
Official OHRRPGCE Wiki and FAQ
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
bis_senchi




Joined: 08 Jun 2004
Posts: 460
Location: Reims, France

PostPosted: Sun May 07, 2006 9:26 pm    Post subject: Another problem solved and a new one to solve ^_^| Reply with quote

I'm glad to tell you that my pause and unpaused scripts work.

Razz Razz
Could somoene confirm me that in my script as it is written (and posted), the old time datas and restored as I press for the second time the numlock key?

Anyway... Here's another problem. I'm using the bank store system made bu Andrusi. You read the aricile in the wiki here :
http://www.hamsterrepublic.com/ohrrpgce/index.php/How_do_I_make_a_Bank_where_you_can_store_money/items_.html

Could somoene tell me where EXACTLY I'm supposed to key in the following code ?

Code:

Withdraw from Savings
 Current Balance: ${V63}
 Cash On Hand: ${V64}

 Withdraw Amount: ${V65}


Code:

Deposit into Savings
 Current Balance: ${V63}
 Cash On Hand: ${V64}

 Deposit Amount: ${V65}


I've keyed them in just as normal text but it appears to have no effects...
Thanks once more! It's so......helpful ^_^| Good luck in making your games!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Gizmog1
Don't Lurk In The Bushes!




Joined: 05 Mar 2003
Posts: 2257
Location: Lurking In The Bushes!

PostPosted: Sun May 07, 2006 9:35 pm    Post subject: Reply with quote

Just a regular textbox, and make sure you follow ALL the instructions. The part that makes it work is after that. You do NOT put that part into the script.
Back to top
View user's profile Send private message Send e-mail AIM Address
bis_senchi




Joined: 08 Jun 2004
Posts: 460
Location: Reims, France

PostPosted: Wed May 10, 2006 1:11 am    Post subject: Problem particially solved Reply with quote

I've started to work on and one of my problems comes from a confusion between {and (

I can now see 0 but I sill can't deposit money. Anyway could somoene confirm me that in my unpaused script the time datas stored in my pause script will be written in the global and make my pause script really a pause script.

Thanks in advance!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
msw188




Joined: 02 Jul 2003
Posts: 1041

PostPosted: Thu May 11, 2006 10:32 am    Post subject: Reply with quote

The symbol { should not be used when writing scripts at all. This symbol is used in the text-box editor in custom to type in special codes that show up as numbers in the text box while playing the actual game. On the other hand, the symbol ( has no special meaning in the textbox editor at all. If there are instructions dealing with {, then they are probably meant for the textbox editor in custom, while instructions involving ( are probably dealing with scripts. I hope that this helps.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Goto page 1, 2, 3, 4  Next
Page 1 of 4

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group