1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

baserCMSのWEBAPI機能をゲーム開発に利用する

Posted at

作ったもの

解説

baserCMSのカスタムコンテンツはwebapiが付属しています。

baserCMSwebapiドキュメント

godot httpリクエストのドキュメント

ゲームシーン.png

ゲームシーンにGDスクリプトをアタッチして以下のようなスクリプトを書く

extends GameScene

@onready var http_request = HTTPRequest.new()
@onready var label = $UI/UIObjectRoot/Label

func _ready():
	add_child(http_request)
	# API 呼び出し
	http_request.request_completed.connect(_on_request_completed)

	var url = "http://〇〇/baser/api/bc-custom-content/custom_entries/1.json?custom_table_id=3"
	http_request.request(url)
	
func _on_request_completed(result, response_code, headers, body):
	if response_code == 200:
		var json = JSON.parse_string(body.get_string_from_utf8())
		label.text = json["entry"]["title"]  # APIレスポンスをLabelに差し込む
	else:
		label.text = "エラー: " + str(response_code)

「$」はアタッチしたスクリプト以下のノードを最も簡単に取得できる方法

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?