Anyone remember Moria?

Game development specific discussions.
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Post by counting_pine »

I can't reproduce this.

Code: Select all

Sub Alpha (Byref test As String)
    
    test = "Hello"
    Print test
    
End Sub

Sub Beta ()
    
    Dim testing As String
    
    testing="Tom"
    
    alpha (testing)
    Print testing
    
End Sub

Dim teststr As String

teststr = "erase"

alpha (teststr)

Print teststr

beta
I get all Hellos.

What version of FB are you using? Is that the entire code?
CommanderRaven
Posts: 86
Joined: Jan 22, 2009 18:52
Location: Houston, tx

Post by CommanderRaven »

counting_pine wrote:I can't reproduce this.

Code: Select all

Sub Alpha (Byref test As String)
    
    test = "Hello"
    Print test
    
End Sub

Sub Beta ()
    
    Dim testing As String
    
    testing="Tom"
    
    alpha (testing)
    Print testing
    
End Sub

Dim teststr As String

teststr = "erase"

alpha (teststr)

Print teststr

beta
I get all Hellos.

What version of FB are you using? Is that the entire code?
Hello, I'm using the lastest version on this site version 0.20. I don't have any patches.

All I can tell you is this sub ...

Code: Select all

Sub get_name ()

	prt("Enter your player's name  [press <RETURN> when finished]",22,3)
	get_string(py.misc.name,3,11,24)
	py.misc.name=temp_str1  '                        patch to fix broken byRef string bug
	clearscn(21,1)

End Sub
When it calls this function.... the byref does not work. But if I call this function from the main code it does work.


Code: Select all

function get_string (ByRef in_str As String,row As integer,column As integer,slen as integer ) As Byte  '  -------  Patched for ByRef bug in FB

	Dim start_col As Integer
	Dim END_col As Integer
	Dim i1 as Integer
	Dim x As String
	Dim tmp as vtype
	Dim flag As Byte
	Dim aborter As Byte
	Dim VALUE As Byte
	Dim Start_column As Integer
	
	start_column = column
   aborter = 0
	flag = 0
	in_str = ""
   put_buffer(pad(in_str," ",slen),row,column)
   put_buffer("",row,column)
	start_col = column
	END_col = column + slen - 1
	put_buffer("_",row,column)
	Do
		Do 
			x=InKey
			If x="" Then Sleep 10
		Loop Until (x<>"")
		
		If Asc(x)=3 Or Asc(x)=25 Or Asc(x)=26 Or Asc(x)=27 Then
			put_buffer(" ",row,column)
			aborter=1
		Else 
			If Asc(x)=13 Then
				put_buffer(" ",row,column)
				flag=1
			Else
				If Asc(x)=8 Then
					column=column-1
						If column<start_column Then column=start_column
					put_buffer("_ ",row,column)
					in_str = Left(in_str,Len(in_str)-1)
				Else
					tmp = x
					put_buffer(tmp+"_",row,column)
					in_str = in_str + tmp
					column = column + 1
					if (column > END_col) Then 			
						flag =1
						put_buffer(" ",row,column)
					End If
				EndIf 
			EndIf
		EndIf
	Loop until (flag=1 or aborter=1)
 
	If (aborter=1) Then 
		VALUE = 0
	Else
      i1 = Len(in_str)
      If (i1 > 1) Then
       	Do while ((RIGHT(in_str,1) = " ") and (i1 > 1)) 
				i1 = i1 - 1
            in_str = Left(in_str,i1)
       	Loop
      EndIf  
      VALUE = 1
   EndIf 

temp_Str1=in_str

Return VALUE
end Function
If I put a print in_str right before the return I see that it has the right value.

I call this function from main program, ie not another sub or function, it returns the value.

But when called from a sub as above. Nothing is returned.

Keep in mind this isn't my code. I just ported it as closely as I could from the Pascal code.

I literally just taking the original code, and making it work in Free Basic.

As I said it didn't see this behavor from all of my subs or functions. I'll release my converted code in a couple of weeks. You can study it all your want!!! However the above sub, when call this function, always failed to return a string value.
agamemnus
Posts: 1842
Joined: Jun 02, 2005 4:48

Post by agamemnus »

Do you use any pointers at all? It's possible you have a memory overflow bug which affects the behavior of strings -- I've been there!

Try using the latest SVN compiler.
http://www.freebasic-portal.de/download ... ailybuilds


This works as expected.

Code: Select all

Sub Alpha (Byref test As String)
test = "Hello"
Print test
End Sub

Sub Beta ()
Dim testing As String
testing="Tom"
alpha (testing)
Print testing
End Sub

Dim teststr As String
teststr = "erase"
alpha (teststr)
Print teststr
beta
sleep
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Post by counting_pine »

What's py.misc.name? Is it a String?
Perhaps it's a String*n? That might have an effect.
rdc
Posts: 1741
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Post by rdc »

You can replace that whole mess with a simple Input statement. Pascal of that time did not have a string data type. They used arrays to hold strings much like C ended up doing. That whole sub is just getting a string from the user and emulating some editor keys to do it.
CommanderRaven
Posts: 86
Joined: Jan 22, 2009 18:52
Location: Houston, tx

Post by CommanderRaven »

counting_pine wrote:What's py.misc.name? Is it a String?
Perhaps it's a String*n? That might have an effect.
I was just thinking about that.

When I setup the TYPES module I tried to setup types that were as close to identical to the original Pascal code.

It used a lot of fixed length strings, so I set them up that way.

But you can't pass fixed length strings in functions.

So that might be the problem.

I'll try change all of them to plain variable length "string"s and see what happens.

Thanks for the link to the daily builds. I'll have to give that a try.
CommanderRaven
Posts: 86
Joined: Jan 22, 2009 18:52
Location: Houston, tx

Post by CommanderRaven »

rdc wrote:You can replace that whole mess with a simple Input statement. Pascal of that time did not have a string data type. They used arrays to hold strings much like C ended up doing. That whole sub is just getting a string from the user and emulating some editor keys to do it.
True but you can't really control where the Input gets it's input from on the screen.

I also wanted to leave all of the original code as is, as much as possible.

Just to make is authentic as possible.

The funny thing is this. He wrote the came in such a way that only one produre prints. About 4 procedures can print different things, but they all go through that one procedure.

So screen display is actually quite easy. I just had to make one procedure to print to the screen.

Which the original DEC dump terminals VT52, VT100, Vt220 etc, had a 80 rows by 24 col screen.

I replace his input/output module with a draw string statement, and there you have a display.

Input works much the same way.
CommanderRaven
Posts: 86
Joined: Jan 22, 2009 18:52
Location: Houston, tx

Post by CommanderRaven »

counting_pine wrote:What's py.misc.name? Is it a String?
Perhaps it's a String*n? That might have an effect.
I changed all of my Type definations from fixed length to plain strings and removed my patch code.

That seems to have fixed that bug. I also upgraded my compiler to the latest version.

It's great to see that work is still being done on FB. A lot people have, including myself, wondered why there hasn't been any updates to the compiler in so long. I'll have to dig through the new features to see if I see anything useful.
CommanderRaven
Posts: 86
Joined: Jan 22, 2009 18:52
Location: Houston, tx

Post by CommanderRaven »

[quote="agamemnus"]Do you use any pointers at all? It's possible you have a memory overflow bug which affects the behavior of strings -- I've been there!

Try using the latest SVN compiler.
http://www.freebasic-portal.de/download ... ailybuilds
quote]

I don't have any pointers, but I think the problem was a combination of fixed length strings and using variable length strings in functions and subs.

But thanks for the link to the lastest build. Looks like a lot of new features and bug fixes in the lastest build. Great to see that work is still be done on FB!
rdc
Posts: 1741
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Post by rdc »

CommanderRaven wrote:True but you can't really control where the Input gets it's input from on the screen.
Use the Locate statement to position the cursor.

Code: Select all


Dim s As String

Locate 10, 10
Input "Enter name: ", s
Locate 1, 1
Print s
Sleep
CommanderRaven
Posts: 86
Joined: Jan 22, 2009 18:52
Location: Houston, tx

Post by CommanderRaven »


Use the Locate statement to position the cursor.
There's a locate command? How the devil did I miss that one! DOH!

There's a future reason I can't use the input command (Unless I want to figure out how to spawn a task).

But that'd really helpful to know it's out there.
sir_mud
Posts: 1401
Joined: Jul 29, 2006 3:00
Location: US
Contact:

Post by sir_mud »

If you need non blocking input I made a Input object system a long time ago http://www.freebasic.net/forum/viewtopic.php?t=6574
The latest and most likely to work is the InputEx object posted later in the thread. I haven't touched this code in some time so I can't guarantee it will work with the latest compiler but it should. I'm about to go to work so I can't do any indepth on it now but I will after and maybe even post an improved version.
CommanderRaven
Posts: 86
Joined: Jan 22, 2009 18:52
Location: Houston, tx

Post by CommanderRaven »

Beta 1 is coming folks!

Here's the new title screen..

Image

I've got to finish the screen options for foreground/background color.

Then it's on to save game and load game.

I should have it all finished sometime tomorrow. Then I'll do a some debuging. I want to get store selling working. I walk to to look at the hallways always staying lit up. I think they didn't do that. I think I've got a bug that leaves the hallways on.

Anyway, after I check those two out, I'll zip up Beta 1 and post it on my site.

It's gonna have bugs. So please document everything you can and email me what you can.

Install will be you simply create a folder, unzip the zip file into the folder. Run Moria.exe. I'll try to do an installer package once I get to RC1.

Moria should run on XP, Vista, and Windows 7. Might run on 2000, or 9x. But I don't have anyway of testing that anymore.

Don't have any idea of memory requirements yet. But I can't see it taking that much! Not yet anyway!

Processor requirements should be, do you have a CPU.. Check!


I'll announce as soon as the Beta 1 is online.
Jocke The Beast
Posts: 272
Joined: May 28, 2005 10:21
Contact:

Post by Jocke The Beast »

Nice information. Looking forwards to tomorrow!
CommanderRaven
Posts: 86
Joined: Jan 22, 2009 18:52
Location: Houston, tx

Post by CommanderRaven »

Jocke The Beast wrote:Nice information. Looking forwards to tomorrow!
I got good news, and bad news. I got most of the code finished for the beta. Really all I got left it change the high score code so if you load a game and are already on the high score list, it won't put you on the list twice.

But the real problem is I've got problems with the save game, and load routine. Even without encryption turned on, It's not working. I get some of the game data loaded, but not all of it.

I've worked on Moria for about 17 hours today. Time for some sleep..

Tomorrow I'll tear that part of the code apart and try to figure out the problem.

Hopefully tomorrow I'll get Beta 1 out the door.
Post Reply