Message Board


Message Board > Fenix / Bennu / Gemix / DIV > fopen(); fclose() etc

December 18, 2006, 13:46
Dennis
どこかにいる
2092 posts

Hi, I have following code. (simplified)

Code:
            s_file_txt = input();
            while(get_id(type input)) frame; end
            f_id = fopen(s_file_txt,O_WRITE);
            fwrite(f_id,level);
            fclose(f_id);

process string input()
private
   string typed_text;
begin
      loop
         //let user type something
      end
      say(typed_text);
      return typed_text;
end


Noz the problem is not that it does not work, because it does. Only the file name is not what I type in the program, but a number of 5 digits such as 65859, it is always different. I think it returns the address of the string rather than the string itself. (bug?) I checked the typed_text, it DOES contain the value of the typed text. I can solve it with a global variable but there must be a better solution... if not I'll use a global variable.
____________
Kwakkel
#
December 18, 2006, 13:57
Rincewind
programmer
1545 posts

The problem is that you are using a process as if it were a function! Processes run semi-parallel and cannot return an actual value when using "return".

Quoting Dennis:
s_file_txt = input();

That gives you the ID of the process input().

I don't know what Fenix version you are using, but any higher version than 0.84a has functions.

[Edited on December 18, 2006 by Rincewind]
____________
Personal website: http://www.loijson.com
#
December 18, 2006, 14:45
Dennis
どこかにいる
2092 posts

I am using 0.84a. I cannot use functions. Global variable then. when I return a variable, then it gets caught in the equation, no?

process string input() works though
____________
Kwakkel
#
December 18, 2006, 15:02
Rincewind
programmer
1545 posts

Quote:
when I return a variable, then it gets caught in the equation, no?


I don't know what you mean by that.

You cannot return a variable with a process yourself. As soon as you call the process the way you do s_file_txt immediatly gets the value of the ID of the input() you just called.

[Edited on December 18, 2006 by Rincewind]
____________
Personal website: http://www.loijson.com
#
December 18, 2006, 15:12
Dennis
どこかにいる
2092 posts

program wafels;
private
int it;

begin
it = 88;
write_int(0,20,20,0,&it);
while(key(_enter)) frame; end
it = eatme();
end

process eatme()
private
v = 10;
begin
return v;
end

this will display "88" and when pressed enter "10". But for strings it does not work.

anyway it works now with global variable.

[Edited on December 18, 2006 by Dennis]
____________
Kwakkel
#
December 18, 2006, 15:31
Rincewind
programmer
1545 posts

Hey, wow, that's interesting. I didn't know you could do that. It seems that a process functions like a function when there is no frame in the process, and that it then also can return a value other than the ID. As soon as it runs into a frame command though it returns the ID.

So this is probably also the solution to your problem (don't have a frame anywhere in the process you are trying to use as a function, because then it returns the ID).

Edit: No it doesn't work with strings indeed. Strange. Partial function behaviour for processes without a frame, but strictly limited to ints? :F

You could try using the new fenix version, v0.86e recently came out, you can download it here: http://www.filehosting.cc/file … -0-86e-zip.html

[Edited on December 18, 2006 by Rincewind]
____________
Personal website: http://www.loijson.com
#
December 18, 2006, 15:42
Dennis
どこかにいる
2092 posts

Nah i want a version that works 100% good with network.dll. mebbe later.
____________
Kwakkel
#
December 19, 2006, 19:38
yonni
None
420 posts
as far as I was aware you are only able to return integers. Could you save the string you want to return as a variable, then return a pointer to that variable and get around the problem this way?
____________
#
December 19, 2006, 20:51
Eckolin
Quite Whiskered
388 posts

Quoting "Input.fh":
process input_stuff(string pointer s, int pointer enter_pressed);


Return variables!
____________
Maker of Games...
Wisdom is supreme; therefore get wisdom.
Need help with coding? I probably wrote something similar.
#
December 20, 2006, 15:27
t money
MRF
22 posts

you can get it to return things other than an int, i posted a thread about this a while back. in your code you have to have the function/process ahead of the function/process calling it:

process string i_return_strings();
BEGIN
RETURN ("hello world");
END

process i_call();
BEGIN
my_string=i_return_strings();
END

(if the order is switched around it won't work. the calling process will take the data as an int instead of what you want it to be.)


so in denis' example, it won't work because the call comes before the code for the process which is acting like a function.

[Edited on December 20, 2006 by t money]
____________
surrogate: wink... did you say wink, or did you wink?

michael: he said that too dad.
#
December 20, 2006, 16:36
Rincewind
programmer
1545 posts

Thanks for clearing that up T money. You know it's kind of sad that the order of processes/functions is of any importance, it's probably such a source of frustation when making use of things where it matters.
____________
Personal website: http://www.loijson.com
#
December 21, 2006, 04:20
t money
MRF
22 posts

it's actually not uncommon. this is why in c++ you need to prototype your functions. i think the best way to deal with it in fenix is to put all your functions (or processes which act like functions) in a seperate "include" file and just make sure it's the first "include" in your prg. should make things easier.
____________
surrogate: wink... did you say wink, or did you wink?

michael: he said that too dad.
#
December 21, 2006, 18:43
yonni
None
420 posts
surely the pointer method would preserve memory (as you are only sending a memory address rather than a whole new string. But I suppose in context the memory saved is negligable.
____________
#
December 21, 2006, 18:51
t money
MRF
22 posts

if you're concerned about the memory space difference between an address (pointer) and a string, you probably shouldn't be using graphics in your game.
____________
surrogate: wink... did you say wink, or did you wink?

michael: he said that too dad.
#
December 22, 2006, 00:22
yonni
None
420 posts
Hence:-
Quoting me:
in context the memory saved is negligable

____________
#

Message Board > Fenix / Bennu / Gemix / DIV > fopen(); fclose() etc

Quick reply


You must log in or register to post.
Copyright © 2005 Booleansoup.com
Questions? Comments? Bug reports? Contact us!