Project X Forums



It is currently Sat Apr 21, 2018 5:45 am

All times are UTC




Post new topic Reply to topic  [ 14 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Beginner problems
PostPosted: Mon Jun 21, 2010 2:52 pm 
Offline
User avatar

Joined: Mon Jun 21, 2010 2:10 pm
Posts: 40
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;


Top
 Profile  
Reply with quote  
 Post subject: Re: Beginner problems
PostPosted: Mon Jun 21, 2010 8:16 pm 
Offline

Joined: Fri May 28, 2010 1:05 pm
Posts: 11
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Beginner problems
PostPosted: Tue Jun 22, 2010 1:45 pm 
Offline
Site Admin
User avatar

Joined: Mon Aug 17, 2009 12:29 pm
Posts: 91
I believe Entuser made a script like that a long time ago, ask Undefined for it.


Top
 Profile  
Reply with quote  
 Post subject: Re: Beginner problems
PostPosted: Tue Jun 22, 2010 4:24 pm 
Offline
User avatar

Joined: Mon Jun 21, 2010 2:10 pm
Posts: 40
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;


Top
 Profile  
Reply with quote  
 Post subject: Re: Beginner problems
PostPosted: Wed Jun 23, 2010 12:35 pm 
Offline
Site Admin
User avatar

Joined: Mon Aug 17, 2009 12:29 pm
Posts: 91
You are not setting StartX anywhere.


Top
 Profile  
Reply with quote  
 Post subject: Re: Beginner problems
PostPosted: Thu Jun 24, 2010 10:56 am 
Offline
User avatar

Joined: Mon Jun 21, 2010 2:10 pm
Posts: 40
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;


Top
 Profile  
Reply with quote  
 Post subject: Re: Beginner problems
PostPosted: Fri Jun 25, 2010 8:03 am 
Offline
Site Admin
User avatar

Joined: Mon Aug 17, 2009 12:29 pm
Posts: 91
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Beginner problems
PostPosted: Fri Jun 25, 2010 12:12 pm 
Offline
User avatar

Joined: Mon Jun 21, 2010 2:10 pm
Posts: 40
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Beginner problems
PostPosted: Fri Jun 25, 2010 2:17 pm 
Offline
Site Admin
User avatar

Joined: Mon Aug 17, 2009 12:29 pm
Posts: 91
Could you copy the errors here?


Top
 Profile  
Reply with quote  
 Post subject: Re: Beginner problems
PostPosted: Fri Jun 25, 2010 9:21 pm 
Offline
User avatar

Joined: Mon Jun 21, 2010 2:10 pm
Posts: 40
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?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Skin by Lucas Kane