ページ 11

タイトル作成でのエラー

Posted: 2010年11月29日(月) 13:38
by 名無し
#include "GV.h"

void title_disp(int x , int y , char title[] , const char **str , int &menu ){
int num=0;
int dx=0,len=0;
const char **str2 = str;

//タイトル表示
dx = x - GetDrawFormatStringWidthToHandle( font[1], title ) / 2;
DrawFormatStringToHandle( dx, y, color[0], font[1], "%s", title );
y += 30; //改行

//情報の取得
while ( strcmp( *str2, "NULL" ) != 0 )
{
if( len < GetDrawFormatStringWidthToHandle( font[0] , *str2 ) )
{
len = GetDrawFormatStringWidthToHandle( font[0] , *str2 );
}
++num;
*str2++;
}
dx = x - len / 2;

//選択制御
if( CheckStatePad(configpad.up) == 1 && menu > 0 )
--menu;
else if( CheckStatePad(configpad.up) == 1 )
menu = num-1;
if( CheckStatePad(configpad.down) == 1 && menu < num-1 )
++menu;
else if( CheckStatePad(configpad.down) == 1 )
menu = 0;

y += menu * 20;
SetDrawBlendMode( DX_BLENDMODE_ALPHA , 100 ) ;
DrawBox( dx-10 , y , dx+10 + len , y + 18 , color[5] , TRUE ) ; //選択位置の表示
SetDrawBlendMode( DX_BLENDMODE_NOBLEND , 0 ) ;
y -= menu * 20;

//項目の表示
while ( strcmp( *str, "NULL" ) != 0 )
{
dx = x - GetDrawFormatStringWidthToHandle( font[0] , *str ) / 2;
DrawFormatStringToHandle( dx, y, color[0], font[0], "%s", *str++);
y += 20;
}
}

void game_start(){
// constでデータが書き換わらないようにする
const char *str[] =
{
{"START"},
{"EXIT"},
{"NULL"} // NULL文字列で終了を示す(小文字不可)
};
static int menu;

title_disp( FIELD_X+FIELD_MAX_X/2 , FIELD_Y+FIELD_MAX_Y/3 , " " , str, menu );

if( CheckStatePad(configpad.shot) == 1 )
{
switch(menu)
{
case 0:
func_state = 99; //メインに戻る
break;
case 1:
printfDx("不明なメニューが選択されました ");
break;
}

}
}


void title_main(){
title_disp();
game_start();
}


上のプログラムを打ってタイトルを作ろうとしたところ

’title_disp’関数に 0 個の引数を指定できません。
とエラーが出ました。

どこを修正することで治せるでしょうか?

Re: タイトル作成でのエラー

Posted: 2010年11月29日(月) 13:42
by ookami
> ’title_disp’関数に 0 個の引数を指定できません。

ということは、

> title_disp();

の部分に問題があります。
宣言を見ると、

void title_disp(int x , int y , char title[] , const char **str , int &menu )

となっているので、
この関数には、5つの引数がないといけませんね。

Re: タイトル作成でのエラー

Posted: 2010年11月29日(月) 13:47
by softya(ソフト屋)
void title_disp(int x , int y , char title[] , const char **str , int &menu ){
と定義されていますので引数は必須です。
ところが、

コード:

void title_main(){
	title_disp();
	game_start();
}
title_disp();では引数がありません。
これがエラーの原因です。

あと、コードタグを使ってもらうと読みやすくなるので次回からは使ってくださいね。

Re: タイトル作成でのエラー

Posted: 2010年11月29日(月) 14:09
by 名無し
void title_main(){
title_disp();
game_start();
}

からtitle_disp();消去で起動しました ありがとうございます

Re: タイトル作成でのエラー

Posted: 2010年11月29日(月) 14:11
by Wpa
ども、
ソフト屋さんのを解釈すると
こうです
void title_disp(int x , int y , char title[] , const char **str , int &menu )
こうなってますね
なら、関数を呼び出したときにはこう書きます

void title_main(){
int x
int y
char title[]
const char **str
int &menu //めんどくさいですがいちいち呼び出します
void title_disp(x,y ,title[] ,**str,&menu );
game_start();
}
つまり()内に宣言を書くと結構メンドイです(利点や特徴を知らない私が言いますので、あしからず)

Re: タイトル作成でのエラー

Posted: 2010年11月29日(月) 16:04
by softya(ソフト屋)
名無し さんが書きました:void title_main(){
title_disp();
game_start();
}

からtitle_disp();消去で起動しました ありがとうございます
それは結局呼び出しを無くしただけで解決になっているんでしょうか?

それと、Wpaさん。
そのコードはサンプルとしてやばいです。

Re: タイトル作成でのエラー

Posted: 2010年11月29日(月) 16:56
by Wpa
サーセン適当に書いたのでw
まあ、
void title_disp(x,y ,title[] ,**str,&menu );
↑これを覚えてもらえばいいってことです
全部見てないのでこれくらいしかいえません。
また、間違えがあれば訂正または注意してもらってかまいません
あと、ついでに初歩的ですが考え方が楽なパターンも紹介します

int y=200;
int x=250;
void opening_disp(int White){ //色の取得


DrawString( x , y , "■" , White );
DrawString( 270 , 200 , "GAME START" , White );
DrawString( 270 , 250 , "未設定" , White );
DrawString( 270 , 300 , "未設定" , White );
DrawString( 270 , 350 , "終了" , White );
}
void opening_control(){
int White;
White = GetColor( 210 , 220 , 255 ) ;

opening_disp(White);

if(CheckStatePad(configpad.down)==1){
y+=50;
if(y==400){
y=200;
}
}
if(CheckStatePad(configpad.up)==1){
y-=50;
if(y==150){
y=350;
}
}
if(CheckStatePad(configpad.shot)>0){
if(y==200){

func_state=99;

}
if(y==350){

DxLib_End();//DXライブラリ終了処理
}
}
}

理屈は簡単です
ショットボタンを押して
yが200だったらゲームスタート
yが350だったらライブラリ終了です(龍神録はDX使ってましたよね?)
ってな感じです
あとは

void title_main(){//整理用にあるだけ
void opening_control()
//opening_dispは↑ですでに呼んでいるのでいりません
}

これで完成ですかね?
コード形式はコピペするとメンドいのでやめました

Re: タイトル作成でのエラー

Posted: 2010年11月29日(月) 17:24
by ookami
> サーセン適当に書いたのでw
> まあ、
> void title_disp(x,y ,title[] ,**str,&menu );
> ↑これを覚えてもらえばいいってことです

いやその部分がまずいですねww
細かく指摘したほうがいいんでしょうかどうでしょうかwww

Re: タイトル作成でのエラー

Posted: 2010年11月29日(月) 17:38
by Wpa
結構アバウトに覚えてるので、教えてもらえると助かります・・・
・・・あれ?よう見たら
main関数に入れるものじゃないですねこれ
しっかり見ない自分があほだったという事ですか・・・w
自分の言ってることの何がおかしいか理解しました。どうも失礼。