HSPポータル
サイトマップ お問い合わせ


HSPTV!掲示板


未解決 解決 停止 削除要請

2017
0211
ぜろ長押しの時はキーを検出したに一回だけだとできません。8解決


ぜろ

リンク

2017/2/11(Sat) 14:37:09|NO.78225

これを実行してるときにスペースを押すと左上にメニューが開いて、ドラクエの選択画面みたいなのがでるはずなんですけど、長押しの時はできてたのに、一回だけ検出するようにしたらメニューを開けなくなってしまいました。
一回だけにしたい理由は、長押しの状態だと、たとえばアイテムのらんを開いたときに次のページのポーションまで一緒に選んでしまうからです。
困っているのは、ラべル*command以降のstickとかです。教えてくれる方いませんか。

randomize
screen 0,640,640,,0,0
横=40:縦=40
sdim bag,5,5
repeat 5
bag(cnt)=1
loop
sdim masu,2,横,縦
playerx=20:playery=2:masu(playerx,playery)="@";プレイヤーの初期位置

*idounoato
repeat 縦
ct=cnt
repeat 横
masu(cnt,ct)="";白紙にする
loop
loop

repeat 800
x=rnd(40)
y=rnd(40)
masu(x,y)="壁";壁を書いて
loop
repeat 5
x=rnd(40)
y=rnd(40)
masu(x,y)="1"
loop
x=rnd(40)
y=rnd(40)
masu(x,y)="移";移動を書く


*main
redraw 0
color 0,0,0:boxf
repeat 縦
ct=cnt
repeat 横:color 255,255,255:pos 16*cnt,16*ct : mes masu(cnt,ct):loop
loop
gosub *idouseigyo
gosub *map_move;masu()に@を入れる前にこれが必要
color 255,255,255:masu(playerx,playery)="@"
gosub *command
redraw 1
await 100
goto *main
*idouseigyo
stick key,15
if key=1{
playerx--;左
if playerx<0:playerx++:goto *jump1;画面から出ないようにする
if masu(playerx,playery)="壁":playerx++:goto *jump1;障害物がある場合移動しない

masu(playerx+1,playery)="";左に移動した場合 右にいた時のを消す
}
if key=2{
playery--;上
if playery<0:playery++:goto *jump1;画面から出ないようにする
if masu(playerx,playery)="壁":playery++:goto *jump1;障害物がある場合移動しない

masu(playerx,playery+1)="";上に移動した場合 下にいた時のを消す
}
if key=4{
playerx++;右
if playerx>横-1:playerx--:goto *jump1;画面から出ないようにする -1は必要
if masu(playerx,playery)="壁":playerx--:goto *jump1;障害物がある場合移動しない

masu(playerx-1,playery)="";右に移動した場合 左にいた時のを消す
}
if key=8{
playery++;下
if playery>縦-1:playery--:goto *jump1;画面から出ないようにする -1は必要
if masu(playerx,playery)="壁":playery--:goto *jump1;障害物がある場合移動しない

masu(playerx,playery-1)="";下に移動した場合 上にいた時のを消す
}
*jump1
return

*map_move
if masu(playerx,playery)="移"{
goto *idounoato
}
return
*command
stick key_space,0
if key_space=16{
arrow_pos=0
command_sw=1
goto *menu
}
return

*menu
redraw 0
color 0,0,0:boxf 0,0,100,100
color 255,255,255
pos 20,0:mes "壁を掘る"
pos 20,20:mes "アイテム"
pos 20,40:mes ""+HP
pos 0,20*arrow_pos:mes "→"
stick arrow_key
if arrow_key = 2{;上
arrow_pos--
if arrow_pos<0:arrow_pos++
}
if arrow_key = 8{;下
arrow_pos++
if arrow_pos>1:arrow_pos--
}
stick esc_key;メニューを閉じる
if esc_key=128:goto *main

stick key_enter;決定
if key_enter=32&&arrow_pos=0{;壁を掘るを選んでる
*uketuke
redraw 0
color 255,0,0
pos playerx*16,playery*16-10:mes "↑"
pos playerx*16+10,playery*16:mes "→"
pos playerx*16,playery*16+10:mes "↓"
pos playerx*16-10,playery*16:mes "←"
stick arrow_key
if masu(playerx-1,playery)=""&&masu(playerx,playery-1)=""&&masu(playerx+1,playery)=""&&masu(playerx,playery+1)="":goto *main;4方に壁がないならもどる
if arrow_key=1&&masu(playerx-1,playery)="壁":masu(playerx-1,playery)="":goto *main;左
if arrow_key=2&&masu(playerx,playery-1)="壁":masu(playerx,playery-1)="":goto *main;上
if arrow_key=4&&masu(playerx+1,playery)="壁":masu(playerx+1,playery)="":goto *main;右
if arrow_key=8&&masu(playerx,playery+1)="壁":masu(playerx,playery+1)="":goto *main;下
redraw 1
await 100
goto *uketuke
}
if key_enter=32&&arrow_pos=1{
*uketuke2
redraw 0
color 0,0,0:boxf 100,0,200,100
repeat 5
pos 120,20*cnt:color 255,255,255:mes ""+bag(cnt)
loop
color 255,255,255 :pos 100,20*arrow_pos:mes "→"
stick arrow_key
if arrow_key = 2{;上
arrow_pos--
if arrow_pos<0:arrow_pos++
}
if arrow_key = 8{;下
arrow_pos++
if arrow_pos>4:arrow_pos--
}
stick esc_key;メニューを閉じる
if esc_key=128:goto *main

stick key_enter;決定
if key_enter=32{
if bag(arrow_pos)=1:HP+=20;ポーションで体力20回復
goto *main
}

await 100
redraw 1
goto *uketuke2
}

redraw 1
await 100
goto *menu



この記事に返信する


Cheesehamburg7273

リンク

2017/2/11(Sat) 15:36:06|NO.78226

こちらの環境では一回でも動きましたよ
Windows10+hsp3.4



チャーくん

リンク

2017/2/11(Sat) 16:21:51|NO.78227

あれ…?
87行目のstick、第二パラメータを16にすると動くのですが…
貼ってるやつそのままだと動きませんね

Windows10(32bit)+HSP 3.4



ぜろ

リンク

2017/2/11(Sat) 16:39:32|NO.78228

こちらの環境は
hsp 3.4 + windows 10 です。



ぜろ

リンク

2017/2/11(Sat) 17:30:18|NO.78229

どうしようもないんですか。



ぜろ

リンク

2017/2/11(Sat) 17:36:27|NO.78230

*main
redraw 0
stick space,0
if space = 16 : mes "ハロー"
redraw 1
await 100
goto *main

短いのでやってみたらできました。



ぜろ

リンク

2017/2/11(Sat) 18:29:18|NO.78231

誰か、原因わかる方いませんか。



沢渡

リンク

2017/2/11(Sat) 18:54:13|NO.78233

検証してみた限り、一回のループでstick文を2回以上実行しているせいのようですね。
(「*idouseigyo」直後のstick文と、「*command」直後のstick文)
以下のコードを実行してみれば、何度スペースキーを押しても「1回目」としか表示されないのが
わかると思います。

repeat redraw 0 stick space,0 if space = 16 : mes "1回目" stick space,0 if space = 16 : mes "2回目" redraw 1 await 100 loop
「*idouseigyo」のところでカーソルキーの判定を行った直後に、スペースキーの判定も行ってみてはどうでしょうか。

それから、今回の質問とは関係ありませんが、gosubでサブルーチンに飛んだあと、
returnで戻らずにサブルーチン外にgotoで飛ぶのは厳禁です。
gotoの多用は混乱の元ですから、どうしても必要な時以外は極力使わない方が良いです。



ぜろ

リンク

2017/2/11(Sat) 19:10:43|NO.78234

みなさんありがとうございました!



ONION software Copyright 1997-2023(c) All rights reserved.