Project X Forums
http://px.worms2d.info/forum/

Beginner problems
http://px.worms2d.info/forum/viewtopic.php?f=5&t=77
Page 1 of 2

Author:  Pac-Man [ Mon Jun 21, 2010 2:52 pm ]
Post subject:  Beginner problems

Hi there.

After trying to understand some scripts, I made my own one. The goal of this script is to create a mine at a random position every time a turn begins (just for understand the code, doesn't have any sense though :D). However, my game just crashes, looks like it's in an endless loop? What am I doing wrong?

EDIT: Beginner errors, figured it out, s. below. But how to check if the mine is placed in air and not terrain?
Code:
procedure InitHooks;
begin
  RegisterHook('OnTurnBegin', ON_TURN_BEGIN);
end;

procedure OnTurnBegin;
var
  newmine : TWPobj;
begin
  newmine := MakeMine(GetSyncRandom(1920, 10),GetSyncRandom(696, 10));
end;

Author:  anoamas321 [ Mon Jun 21, 2010 8:16 pm ]
Post subject:  Re: Beginner problems

hmmm could make an fun game on a bigish map, make a mine or barrel ever 2-3 turns. i may give that ago :P

Author:  Gran PC [ Tue Jun 22, 2010 1:45 pm ]
Post subject:  Re: Beginner problems

I believe Entuser made a script like that a long time ago, ask Undefined for it.

Author:  Pac-Man [ Tue Jun 22, 2010 4:24 pm ]
Post subject:  Re: Beginner problems

Yeah, I actually got the idea from that. I just wanted to try that out myself, to understand the language.


Well, in the meantime i made this script. It's like a Fort scheme where invading results in keeping the worm on his own site. But it doesn't do anything now :( what's the problem here? Need some code tips :D

You will probably wonder why I use 960 instead of MapX / 2. Simple answer: because MapX always returns 0 for me!

Code:
var
CurrentWorm : TWPobj;
StartX : Integer;

procedure InitHooks;
begin
  RegisterHook('OnFrame', ON_FRAME);
  RegisterHook('OnTurnBegin', ON_TURN_BEGIN);
end;

procedure OnFrame;
begin
  if CurrentWorm <> nil then begin
    if StartX < 960 then begin
      if CurrentWorm.PosX > 960 then CurrentWorm.PosX := 960;
    end;
    if StartX > 960 then begin
      if CurrentWorm.PosX < 960 then CurrentWorm.PosX := 960;
    end;
  end;
end;

procedure OnTurnBegin;
begin
  CurrentWorm := GetTekWormObj();
  StartX := CurrentWorm.PosX;
end;

Author:  Gran PC [ Wed Jun 23, 2010 12:35 pm ]
Post subject:  Re: Beginner problems

You are not setting StartX anywhere.

Author:  Pac-Man [ Thu Jun 24, 2010 10:56 am ]
Post subject:  Re: Beginner problems

Oops! Oh lol. I didn't see that. Well, beginner problems!
Wait, is this not called? Or is the variable not global?

Code:
procedure OnTurnBegin;
begin
  CurrentWorm := GetTekWormObj();
  StartX := CurrentWorm.PosX;
end;

Author:  Gran PC [ Fri Jun 25, 2010 8:03 am ]
Post subject:  Re: Beginner problems

Whoops, I didn't see that. Try showing some messages at the top with PrintMessage or whatever it's called in 0.6.5, you might figure it out.

Author:  Pac-Man [ Fri Jun 25, 2010 12:12 pm ]
Post subject:  Re: Beginner problems

Yeah, I also wanted to do some debug stuff at the top, but I can't get the command to work. Always syntax error and stuff.

Author:  Gran PC [ Fri Jun 25, 2010 2:17 pm ]
Post subject:  Re: Beginner problems

Could you copy the errors here?

Author:  Pac-Man [ Fri Jun 25, 2010 9:21 pm ]
Post subject:  Re: Beginner problems

Code:
procedure OnTurnBegin;
begin
  CurrentWorm := GetTekWormObj();
  StartX := CurrentWorm.PosX;
  ShowMessageOnTop(23, StartX); //Type mismatch
end;



I think I have to cast StartX to a string, but how?

Page 1 of 2 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/