Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, 7th_zorro, VoroneTZ, Quad), 901 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Help with Centering Function #221047
08/11/08 19:54
08/11/08 19:54
Joined: Aug 2008
Posts: 5
Orlando, Florida
G
Geoff Offline OP
Newbie
Geoff  Offline OP
Newbie
G

Joined: Aug 2008
Posts: 5
Orlando, Florida
Something is wrong with this function and I'm not seeing it.

Input please.

function center_ text(txt)
{
var cen; var len;
len = str_len(txt);
cen = (screenwidth - len) /2) +1;

return(cen);

}

screenwidth is declared as 480. I've also tried hard-coding this value.

thx.

- Geoff

Re: Help with Centering Function [Re: Geoff] #221053
08/11/08 20:29
08/11/08 20:29
Joined: Oct 2002
Posts: 361
Germany Cologne
hack-panther Offline
Senior Member
hack-panther  Offline
Senior Member

Joined: Oct 2002
Posts: 361
Germany Cologne
str_len returns the number of letters, not the size in pixels...

Re: Help with Centering Function [Re: hack-panther] #221133
08/12/08 14:24
08/12/08 14:24
Joined: Aug 2008
Posts: 5
Orlando, Florida
G
Geoff Offline OP
Newbie
Geoff  Offline OP
Newbie
G

Joined: Aug 2008
Posts: 5
Orlando, Florida
Ok, so the math would be off by a multipule of 8 or something, but it would still return a value.

The function actually crashes.

Re: Help with Centering Function [Re: Geoff] #221138
08/12/08 14:30
08/12/08 14:30
Joined: Apr 2008
Posts: 586
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 586
Austria
I see a missing bracket in the "cen" line, a missing type of the txt argument (if no type, it defaults to var)... I doubt that this can even compile.

Re: Help with Centering Function [Re: Petra] #221145
08/12/08 14:47
08/12/08 14:47
Joined: Aug 2008
Posts: 5
Orlando, Florida
G
Geoff Offline OP
Newbie
Geoff  Offline OP
Newbie
G

Joined: Aug 2008
Posts: 5
Orlando, Florida
ok, missed the opening appostophy, but I leaning towards the "txt" not having a type as to why it crashes.

i've tried: center_text(var txt) //does not work
center_text(STRING* txt) // does not work

What am I missing?

Re: Help with Centering Function [Re: Geoff] #221151
08/12/08 14:52
08/12/08 14:52
Joined: Apr 2008
Posts: 586
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 586
Austria
How are you calling that function?

Re: Help with Centering Function [Re: Petra] #221154
08/12/08 14:57
08/12/08 14:57
Joined: Aug 2008
Posts: 5
Orlando, Florida
G
Geoff Offline OP
Newbie
Geoff  Offline OP
Newbie
G

Joined: Aug 2008
Posts: 5
Orlando, Florida
First, I found the problem with the above (stupid stupid stupid)...I had a space between center_ & text so it was not center_text...blah

however, I'm still tring to figure this out and am calling the function from:

TEXT* credits_txt =
{
layer = 15;
pos_x = center_text(credits_str);
pos_y = 10;
string (credits_str);
flags = VISIBLE;
}

Which now errors out at the call.

credits_str was declared like:

STRING* credits_str = "Copyright (c) 2005\nGeoff Doty\n";

Re: Help with Centering Function [Re: Geoff] #221157
08/12/08 15:01
08/12/08 15:01
Joined: Apr 2008
Posts: 586
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 586
Austria
You should have posted that first, then the problem had been obvious.

The first thing you learn in the tutorial is, all commands must be inside a function. TEXT* is not a function, its a text definition.

You need a main() function and in that function, among other things you can call your center_text:

credits_txt.pos_x = center_text(credits_str);

I recommend the lite-c tutorial, there you learn how to write programs.



Re: Help with Centering Function [Re: Petra] #221160
08/12/08 15:14
08/12/08 15:14
Joined: Aug 2008
Posts: 5
Orlando, Florida
G
Geoff Offline OP
Newbie
Geoff  Offline OP
Newbie
G

Joined: Aug 2008
Posts: 5
Orlando, Florida
I did not think lite-c was object orientated.

I was going off of the the tutorial(workshop) # 7, which was listed like this:

////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>
////////////////////////////////////////////////////////////////////
STRING* aloha_str = "Welcome to Paradise Island!";

TEXT* greetings_txt =
{
pos_x = 300;
pos_y = 250;
string (aloha_str);
flags = VISIBLE;
}
////////////////////////////////////////////////////////////////////
function main()
{
video_mode = 7;
screen_color.blue = 150;
}

and wanted to center the aloha_str.

I dont know the restrictions of "pointers", as i'm a run-time programer - vb, php, tcl...ect...

So, I guess the to-self question is that "ALL *pointers* act like structures where I can modify/assign values outside the structure?"


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1