PDA

View Full Version : Goto, Sprites... help! =0



Deckard70
05-02-2008, 09:00 AM
Hello every1!
I'm new to MP and its forum.
I'm just starting writing my first appls with this software.
I have some simply questions:
- Does exist command GOTO in MP? If not, how can I jump forward or backward in my prgm (without using commands repeat-until or forward with procedures)?
- Do exist commands to create sprites?
- Where can I find a complete list of available commands in MP (yes, I read help file in MP)?
Thanx!

jasonf
05-02-2008, 11:00 AM
GOTO was probably not included in this version of Pascal as it's generally seen as "A Bad Thing".

Check the Delphi Basics definition of GOTO and you'll see what I mean.

www.delphibasics.co.uk/RTL.asp?Name=Goto

Pascal is a very elegant language with much better solutions to all coding problems where a GOTO might have originally been used.

I was actually surprised to learn that the GOTO command even existed for Pascal. I thought it was a BASICism.

This is the most I've written the word GOTO in the last 10 years.


I am curious as to why you don't want to or can't use commands like repeat or while? They should be available in the MIDLet Pascal language. I've not personally used it so I don't know for sure, but I'd be very very surprised if they hadn't included such fundamental features in the language.

www.delphibasics.co.uk/ByFunction.asp?Main=PgmStruct&Sub=Loops

www.delphibasics.co.uk is a very good site for a Pascal language reference. (although it does focus on Delphi, it's just the Pascal language with a few extras)

Wikipedia has a page for MIDLet Pascal.
http://en.wikipedia.org/wiki/MIDletPascal

P.S. Welcome to the forum 8)

Deckard70
05-02-2008, 11:58 AM
Procedures and repeat-until command are includeded in MP.
As said I'm new to MP and Pascal itself.
Sure we can do the same without this command, especially if it's so dangerous.
I don't know why some compilers includes Labels + GOTO + more Pascal commands and others don't.
But if MP could do that (without crashing or generating bugs) it would not be such a crime!
For a beginner as I am, It would be interesting to have a complete list of MP commands; somewhere I read the one in MP help file is uncomplete.
P.S. Thank you for your answer :wink:

Deckard70
05-02-2008, 12:02 PM
Do someone have experience of using sprites in MP (also using API gaming support)?

cronodragon
05-02-2008, 07:25 PM
I was actually surprised to learn that the GOTO command even existed for Pascal. I thought it was a BASICism.

I think it's more an ASSEMBLYism. It makes a lot of sense in asm, but not in Pascal, neither in Basic that are teacher languages. Ironically C should have a GOTO, because it seems to approach the lowest level of high level languages. :D

Probably the reason MP doesn't have it, is because the Java virtual machine doesn't allow it :?

Chobley
05-02-2008, 08:27 PM
Ah! I wondered if I was the only person left using MIDlet Pascal...so now at least I know there are at least 2 tumbleweeds in this forum...

I guess you have looked around this forum and have seen this link;

http://piligrim.at.tut.by/java/mp.html

...it seems not active anymore...it was a set of libraries to add sprite capabilities for MIDLet Pascal by Piligrim...unfortunately I'm a beginner too and had trouble understanding how to implement.

However, I've used the LoadImage and DrawImage functions that are within MIDlet Pascal anyway to customise my own "sprites" and used maths X,Y based as well on the size of the images to make my own collision detections, not necessarily pixel perfect in some cases but it has been a start to making games...

Deckard70
06-02-2008, 08:59 AM
Hi Chobley,
I read in the forum about these add-ons for MB
I retrieved this link:
http://piligrim.blog.tut.by/?s=game+support
Hope it's correct. Soon I will make some test.
I arrived to MP very late (and just) 'cause I crashed my old, long lived, basic mobile and I bought my first one with J2me support (SE w810i).
So pascal gurus don't get bored/angry and forget my GOTO question if you find it offensive! :wink: also, expect more beginner query.
Mobilebasic costs too much, is too slow, and it doesn't compile but just converts basic language when prgm runs (read on various net ratings). The only thing interesting may be sprite statements implementation, but I don't have experience about it.
Also I found this:
http://www.tauschke.com/products/uicreator/index.html
They say "you can use every language which can create Midlet forms (like Java, MidletPascal or MobileBasic)"... :roll: It's free for personal use.
I read your sprite "simulation" using MB custom statements. Very interesting for me. How do you delete the previous sprite (image) position before printing the next one? Or this is not a problem using MB graphic statements?

Chobley
06-02-2008, 10:11 AM
Thanks for this updated link;

http://piligrim.blog.tut.by/?s=game+support

I should give it another go...

I THINK I may have used this creator;

http://www.tauschke.com/products/uicreator/index.html

I will check later when I have more time! To be honest if I did; I did not look at it very long as had the PASCAL coding bug at the time - but thanks for this...

and quote;

" read your sprite "simulation" using MB custom statements. Very interesting for me. How do you delete the previous sprite (image) position before printing the next one? Or this is not a problem using MB graphic statements?"

Answer: Basically Refresh the screen; i.e in your game play repaint the back ground, and your "spites"...i.e;

proc RefreshScreen;
DrawImage(Background,0,0);
DrawImage(Sprite,X,Y);
Repaint;
end;

As far as I know there is no UnloadImage(); type command...

P.S. yes...the GOTO and labels: command is sorely missed ! But using logic...i.e boolean conditions you should be able to over come this in your games...

Deckard70
06-02-2008, 02:36 PM
Go..TOmb :( We'll try to survive :thumbup:
Thanx again, Chobley
Just a doubt: using Repaint after every background re-printing command causes a flashing animation?

Chobley
06-02-2008, 04:55 PM
I know what you mean, that's what I thought...(being from a BASIC background in the days of home computers...and...no sprites)

Just make sure you have got everything on screen you wish to show whilst calling Repaint;

When drawing an image or in fact, any other drawing command; it writes stuff to a "buffer" first...so when you call 'Repaint' it appears instantly and flicker free...

Use Repaint when you need it as it is apparently slow, however writing to the "buffer" is not.

Chobley
06-02-2008, 05:06 PM
As cronodragon said

Probably the reason MP doesn't have it, is because the Java virtual machine doesn't allow it :?[/quote][quote]

Interesting point...think that answers why no labels or gotos...i'm a novice at Java by the way, but this sounds like why...

Deckard70
07-02-2008, 08:43 AM
I know there are better and more appropriate ways to create midlets.
But for me this is a hobby, and MP and his friends allow me to recycle old memories of basic programming (waiting days with more spare time to deepen the knowledge of prg languages...)
Here is a small prg I found in a russian (?) forum, as free (public) attachment (it's a simply calculator):

program NewProject;

var
okCommand,sqrCommand,sqrtCommand,IntToHexCommand,q uitCommand,
sinCommand,cosCommand,tanCommand,lnCommand,clicked :command;
IntField:integer;
str:string;
intvalue:integer;
screenWidth, screenHeight: integer;
r:real;

procedure welcomeScreen;
var

textToDisplay : string;
textXPos : integer;
textYPos : integer;
keyCode : integer;
begin
setColor(255, 255, 255);
screenWidth := getWidth;
screenHeight := getHeight;
fillRect(0, 0, screenWidth, screenHeight);
setColor(0, 0, 255);
setFont(FONT_FACE_PROPORTIONAL, FONT_STYLE_BOLD, FONT_SIZE_MEDIUM);
textToDisplay := 'Numeric Converter';
textXPos := (screenWidth - getStringWidth(textToDisplay)) div 2;
textYPos := (screenHeight - getStringHeight(textToDisplay)) / 2;
drawText(textToDisplay, textXPos, textYPos);
textYPos := textYPos + getStringHeight(textToDisplay);
setColor(0, 0, 0);
setFont(FONT_FACE_PROPORTIONAL, FONT_STYLE_PLAIN, FONT_SIZE_SMALL);
textToDisplay := 'Created by Voyager';
textXPos := (screenWidth - getStringWidth(textToDisplay)) div 2;
drawText(textToDisplay, textXPos, textYPos);
textYPos := textYPos + getStringHeight(textToDisplay);
textToDisplay := 'Press any key';
textXPos := (screenWidth - getStringWidth(textToDisplay)) div 2;
drawText(textToDisplay, textXPos, textYPos);
repaint;
repeat
keyCode := getKeyClicked;
until keyCode <0> 0 then
begin
i := IntValue;
while i>0 do
begin
j := i mod 16;
if (j<10) then
s := Chr(Ord('0') + j) + s;
else
s := Chr(Ord('A') + (j - 10)) + s;
i := i div 16;
end;
end;
if Digits <1>0 do
begin
s := '0' + s;
i := i - 1;
end;
IntToHex := s;
end;

Function RealToString(r:real; width:integer):string;
var s1,s2:string;pre:string;
begin
pre:='';
if r<0>5 then width:=5;
if frac(r)>=0.5 then s1:=integertostring(Trunc(r)-1) else s1:=integertostring(Trunc(r));if frac(r)=1/10 then s1:=integertostring(stringtointeger(s1)-1);
if width<=0 then s2:='' else s2:='.'+integertostring(trunc(Trunc(frac(r)*pow(10 ,width))));
if frac(r)=0 then s1:=integertostring(stringtointeger(s1)+1);
if r=0 then RealToString:='0' else RealToString:=pre+s1+s2;
end;

function SqrF(str:string): string;
begin
intvalue:=StringToInteger(str);
SqrF:=IntegerToString(sqr(intvalue));
end;

function SqrtF(str:string): string;
begin
intvalue:=StringToInteger(str);
SqrtF:=RealToString(sqrt(intvalue),5);
end;

function SinF(str:string): string;
begin
intvalue:=StringToInteger(str);
r:=toRadians(intvalue);
SinF:=RealToString(sin(r),5);
end;

function CosF(str:string): string;
begin
intvalue:=StringToInteger(str);
r:=toRadians(intvalue);
CosF:=RealToString(cos(r),5);
end;

function TanF(str:string): string;
begin
intvalue:=StringToInteger(str);
r:=toRadians(intvalue);
TanF:=RealToString(tan(r),5);
end;

function LnF(str:string): string;
begin
intvalue:=StringToInteger(str);
LnF:=RealToString(log(intvalue),5);
end;

begin
welcomeScreen;
okCommand := createCommand('OK', CM_SCREEN, 1);
sqrCommand := createCommand('Sqr', CM_SCREEN, 1);
sqrtCommand := createCommand('Sqrt', CM_SCREEN, 1);
IntToHexCommand := createCommand('Hex', CM_SCREEN, 1);
lnCommand := createCommand('Ln', CM_SCREEN, 1);
sinCommand := createCommand('Sin', CM_SCREEN, 1);
cosCommand := createCommand('Cos', CM_SCREEN, 1);
tanCommand := createCommand('Tan', CM_SCREEN, 1);
quitCommand := createCommand('Quit', CM_EXIT, 1);
showForm;
IntField := formAddTextField('Insert a number:', '', 10, TF_NUMERIC);
repeat
addCommand(sqrCommand);
addCommand(sqrtCommand);
addCommand(IntToHexCommand);
addCommand(lnCommand);
addCommand(sinCommand);
addCommand(cosCommand);
addCommand(tanCommand);
addCommand(quitCommand);
repeat
clicked := getClickedCommand;
delay(100);
until (clicked <> emptyCommand);
if(clicked=quitCommand) then halt;
removeCommand(sqrCommand);
removeCommand(sqrtCommand);
removeCommand(IntToHexCommand);
removeCommand(lnCommand);
removeCommand(sinCommand);
removeCommand(cosCommand);
removeCommand(tanCommand);
removeCommand(quitCommand);
str := (formGetText(IntField));
showCanvas;
setColor(255, 255, 255);
fillRect(0, 0, screenWidth, screenHeight);
setColor(0, 0, 255);
If clicked=IntToHexCommand then drawText(IntToHex(stringtointeger(str),8 ), 5, 5)
else If clicked=sqrCommand then drawText(SqrF(str), 5, 5)
else If clicked=sqrtCommand then drawText(SqrtF(str), 5, 5)
else If clicked=sinCommand then drawText(SinF(str), 5, 5)
else If clicked=cosCommand then drawText(CosF(str), 5, 5)
else If clicked=tanCommand then drawText(TanF(str), 5, 5)
else If clicked=lnCommand then drawText(LnF(str), 5, 5)
else drawText('Invalid command', 5, 5);
repaint;
addCommand(okCommand);
addCommand(quitCommand);
repeat
clicked := getClickedCommand;
delay(100);
until (clicked <> emptyCommand);
removeCommand(okCommand);
removeCommand(quitCommand);
formSetText(IntField,'');
showForm;
until clicked = quitCommand;
halt;
end
I found it very instructive to learn how to use procedure, functions, repeat-until, ifs conditions etc. without missing GOTO statement. A procedure is used for presentation. Main repeat-until cycle contains secondary one (which call the relative functions) ...until prg is halted.

Chobley
07-02-2008, 06:29 PM
That looks a good example...sure I can learn something from it too...I tried it but got a bug on line 44...will look into that when less tired!

Interesting in what you say; I do this as a hobby too...but would not mind actually taking it a little further...

Well, if you got any other great examples or any other questions then post them here...I’m a novice and keen to learn – but will try and answer...or maybe the other PASCAL stalwarts could help us out if we both get stuck!

cronodragon
07-02-2008, 09:00 PM
For your information, I just started a tool to port Object Pascal programs to virtual machines. But I don't know how much time it will take. It will support J2ME, Flash 8 Player, Flash 9 Player, and probably .NET.

Regards!
-Marco

Deckard70
08-02-2008, 08:22 AM
The error is probably in this line:

If clicked=IntToHexCommand then drawText(IntToHex(stringtointeger(str), 8 ), 5, 5)

I had to put a space (" ") between "8" and ")" cause if joined they result as emoticon ( 8) ).
Anyway here's the link where I grabbed the prgm:
http://voyager.alfamoon.com/forum/topic.php?forum=3&topic=42
Cronodragon, we'll stay tuned, keep us informed.

Deckard70
08-02-2008, 08:22 AM
The error is probably in this line:

If clicked=IntToHexCommand then drawText(IntToHex(stringtointeger(str), 8 ), 5, 5)

I had to put a space (" ") between "8" and ")" cause if joined they result as emoticon ( 8) ).
Anyway here's the link where I grabbed the prgm:
http://voyager.alfamoon.com/forum/topic.php?forum=3&topic=42
Cronodragon, we'll stay tuned, keep us informed.

Chobley
08-02-2008, 05:20 PM
Wow cronodragon that sounds a really good idea...best of luck in coding that one! Yep and update here!

Hello gain Deckard70...

Thanks for that link...I got it up and running ok...I don't know if you noticed - but when you translate the page in Google it also shows this link;

http://209.85.135.104/translate_c?hl=en&u=http://www.mirgames.ru/article/mobile/midlet&prev=/search%3Fq%3Dhttp://voyager.alfamoon.com/forum/topic.php%253Fforum%253D3%2526topic%253D42%26hl%3D en

It has demo code here of an up market 'Hello World' type application...

(and no not this type of one;)
10 PRINT "HELLO WORLD"
20 GOTO 10

...just had to get the GOTO on here for old times sake :-)

...but also on there is a tank demo of moving the thing around the screen...might help us both ...eh?

Deckard70
13-02-2008, 02:50 PM
:shock:
Thanks! These little codes can really help us to learn the wisdom of MP language!
..Wondering how to find more sample codes, I tried this search on Google:
Midletpascal+begin+var+procedure+(...any MP command)
This resulted many simply routines added in various forums around the world, some strange ftp link.. and one thing above all: MP has (had) many fans in Russia!

Chobley
13-02-2008, 06:33 PM
It is a shame their website is dead...it had some examples of a Tetris type game and a Minesweeper type game...and they gave you the code as well...

Have you seen Savage's BlitzBomber example? It just shows what you can do with this....make a professional, polished product...like you said before there are other ways of creating MIDlets...it's a clever bit of software with basic (or should that be BASIC?) programming knowledge...

I must admit examples are hard to find, but if I find any other examples out there then I'll stick them on here...

MIDlet Pascal may well be "dead" but so is Elvis...and he still lives on...

:-)

Deckard70
15-02-2008, 04:10 PM
MidlElvis Pascal is back! 8)
Here are some more russian pages (translated).
Interesting how they explain the program structure

http://translate.google.com/translate?u=http%3A%2F%2Fmobimag.ru%2FArticles%2F2 793%2FMIDletPascal_sobiraem_Java-slaidshou_dlya_lyubogo_mobilnogo_primer.htm&langpair=ru%7Cen&hl=it&ie=UTF8

http://translate.google.com/translate?u=http%3A%2F%2Fmobi.ru%2FArticles%2F2684 %2FMIDletPascal_sobiraem_universalnuyu_Java-knigu_dlya_mobilnogo.htm&langpair=ru%7Cen&hl=it&ie=UTF8

paul_nicholls
16-02-2008, 12:17 PM
For your information, I just started a tool to port Object Pascal programs to virtual machines. But I don't know how much time it will take. It will support J2ME, Flash 8 Player, Flash 9 Player, and probably .NET.

Regards!
-Marco

Hi Marco,
I had thought of starting a similar project but hadn't the time...

I was going to start with a pascal parser to create a parse tree that I could then convert to other source code and/or assembly, or byte codes.

Good luck with your project :-)

cheers,
Paul

cronodragon
16-02-2008, 08:01 PM
Hi Marco,
I had thought of starting a similar project but hadn't the time...

I was going to start with a pascal parser to create a parse tree that I could then convert to other source code and/or assembly, or byte codes.

Good luck with your project :-)

cheers,
Paul

Hey, thanks a lot Paul.

I started this project since I was looking for a way to port Pascal to Flash and also to J2ME platforms. The best solution would be to have FPC generate bytecode for those virtual machines. I asked at Lazarus and FPC mailing lists, but they are not interested in modifying it, since that means a "mutilation" of Pascal... something I agree with. But maybe making this project, even if it is unperfect, FPC developers might become interested and add some sort of "paradigm" directive the compiler.

I think Pascal is not only the most elegant language created, it can also be a versatile language that shapes itself to become the tool a developer requires to solve any problem. :D I'm working on beta 0.3, and now it ports simple "Hello World!" programs to Actionscript, compiling with MTASC, an open source AS 2 compiler that is faster and more optimal than Macromedia Flash 8 compiler. Hope to finish this project and that someday it gets completely obsolete by a new version of FPC that compiles bytecode.

paul_nicholls
17-02-2008, 11:52 AM
Hi Marco,
I had thought of starting a similar project but hadn't the time...

I was going to start with a pascal parser to create a parse tree that I could then convert to other source code and/or assembly, or byte codes.

Good luck with your project :-)

cheers,
Paul

Hey, thanks a lot Paul.

I started this project since I was looking for a way to port Pascal to Flash and also to J2ME platforms. The best solution would be to have FPC generate bytecode for those virtual machines. I asked at Lazarus and FPC mailing lists, but they are not interested in modifying it, since that means a "mutilation" of Pascal... something I agree with. But maybe making this project, even if it is unperfect, FPC developers might become interested and add some sort of "paradigm" directive the compiler.

I think Pascal is not only the most elegant language created, it can also be a versatile language that shapes itself to become the tool a developer requires to solve any problem. :D I'm working on beta 0.3, and now it ports simple "Hello World!" programs to Actionscript, compiling with MTASC, an open source AS 2 compiler that is faster and more optimal than Macromedia Flash 8 compiler. Hope to finish this project and that someday it gets completely obsolete by a new version of FPC that compiles bytecode.

I totaly agree and I think Pascal rocks! The project sounds neat, even in this early stage.
I wouldn't mind seeing what you have come up with currently.

Talking about compilers, I did make my own simple Pascal like scripting language a couple of years ago after reading the "Let's Build a Compiler" site http://compilers.iecc.com/crenshaw/ on how to make compilers using Pascal.

It "compiled' the langauge to byte codes that I ran in my own virtual machne. It had subroutines, recursion, and you could register Delphi routines that could be run by the scripting language.

You could also obviously run routines in the scripting language from Delphi as well. I was quite pleased with it at the time :-)

cheers,
Paul

Chobley
17-02-2008, 12:30 PM
MidlElvis Pascal is back! 8)
Here are some more russian pages (translated).
Interesting how they explain the program structure

http://translate.google.com/translate?u=http%3A%2F%2Fmobimag.ru%2FArticles%2F2 793%2FMIDletPascal_sobiraem_Java-slaidshou_dlya_lyubogo_mobilnogo_primer.htm&langpair=ru%7Cen&hl=it&ie=UTF8

http://translate.google.com/translate?u=http%3A%2F%2Fmobi.ru%2FArticles%2F2684 %2FMIDletPascal_sobiraem_universalnuyu_Java-knigu_dlya_mobilnogo.htm&langpair=ru%7Cen&hl=it&ie=UTF8

Thanks for these code examples, it is different from the examples that i learned from in the manual...interestingly there seems to be break command which might help you out of your GOTO dilemma...I've not run any of the code but have bookmarked these. So thanks very much for your help!

Chobley
17-02-2008, 12:36 PM
To; cronodragon and Paul_Nicholls...what you are doing and have done sounds really cool...if you can evolve in PASCAL another way of creating MIDlets then that is good! There seems to be a missing product out there for people that don't want to use over complicated IDE's

paul_nicholls
17-02-2008, 09:59 PM
Hi Marco,
I had thought of starting a similar project but hadn't the time...

I was going to start with a pascal parser to create a parse tree that I could then convert to other source code and/or assembly, or byte codes.

Good luck with your project :-)

cheers,
Paul

Hey, thanks a lot Paul.

I started this project since I was looking for a way to port Pascal to Flash and also to J2ME platforms. The best solution would be to have FPC generate bytecode for those virtual machines. I asked at Lazarus and FPC mailing lists, but they are not interested in modifying it, since that means a "mutilation" of Pascal... something I agree with. But maybe making this project, even if it is unperfect, FPC developers might become interested and add some sort of "paradigm" directive the compiler.

I think Pascal is not only the most elegant language created, it can also be a versatile language that shapes itself to become the tool a developer requires to solve any problem. :D I'm working on beta 0.3, and now it ports simple "Hello World!" programs to Actionscript, compiling with MTASC, an open source AS 2 compiler that is faster and more optimal than Macromedia Flash 8 compiler. Hope to finish this project and that someday it gets completely obsolete by a new version of FPC that compiles bytecode.

Hi Marco,
I have just found your project on sourceforge :-)

https://sourceforge.net/projects/ptvm/


I have downloaded it and am taking a look :-)

Keep up the great work :-)

cheers,
Paul