https://www.youtube.com/watch?v=9wJcIM3zfkw&list=PLRDkUKkyMRU_Kr2yncnDV_HkP-5r07yDW
型のタイプは
string
int
float
宣言
varとつけると変数。varと書かなければ定数。定数は変更できない。
var PlayerName : string = “Enter Name Here”
HP: int = 100
開始時のイベントは
OnBegin<override>()<suspends>:void=
変数のPrintは以下のようにする。
Print(“Name: {PlayerName}”)
変数のセットは先頭にsetをつける。
set PlayerName = “Your Name”
https://www.youtube.com/watch?v=xslYOZrjq2Q&list=PLRDkUKkyMRU_Kr2yncnDV_HkP-5r07yDW&index=2
この動画では変数を使った計算をしている。
・変数などの候補はカーソルキーで選択してTabで決定する。
・メニューの表示タブから「右端で折り返す」をチェックするとコードが見やすくなる。
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.
# A Verse-authored creative device that can be placed in a level
Lesson_02 := class(creative_device):
var PlayerTotalHealth : int = 100
var EnemyAttackDamage : int = 10
var PlayerDefense : int = 5
var SpecialAttackDamage : float = 65.0
var BaseAttackDamage : int = 20
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
Print("Player Health: {PlayerTotalHealth}")
Print("Enemy Attacked Player For {EnemyAttackDamage}Damage")
set PlayerTotalHealth = PlayerTotalHealth - EnemyAttackDamage
Print("Player Health: {PlayerTotalHealth}")
set PlayerTotalHealth -= (EnemyAttackDamage - PlayerDefense)
Print("Player Health After Defense and Attack: {PlayerTotalHealth}")
HealthPotion : int = 20
set PlayerTotalHealth += HealthPotion
Print("Health: {PlayerTotalHealth}")
SpecialAttack01 : float = SpecialAttackDamage / 3.0
Print("Special Attack 01: {SpecialAttack01}")
PowerUpMultiple : int = 3
TempAttackDamage : int = BaseAttackDamage * PowerUpMultiple
UEFN Verse For Beginners Course - Control Flow - Lesson 3
https://www.youtube.com/watch?v=wK9DwM2VGsI
・if, else if, else, then
・GetRandomInt
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/Random }#GetRandomIntのために必要
# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.
# A Verse-authored creative device that can be placed in a level
Lesson_03 := class(creative_device):
var PlayerHealth : int = 100
var EnemyAttackDamage : int = 51
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
Print("Enemy attacks Player.")
set PlayerHealth -= EnemyAttackDamage
if(PlayerHealth <= 0):
Print("Player Died :(")
Print("Player Flinched. Enemy attacks again.")
set PlayerHealth -= EnemyAttackDamage
if(PlayerHealth <= 0):
Print("Player Died :(")
var PlayerDiceResult : int = GetRandomInt(1, 20)
var EnemyDiceResult : int = GetRandomInt(1, 20)
set PlayerHealth = 100
Print("Plyer and Enemy rolled dice")
Print("Player Dice: {PlayerDiceResult}")
Print("Enemy Dice: {EnemyDiceResult}")
if(EnemyDiceResult > PlayerDiceResult):
set PlayerHealth -= EnemyAttackDamage
Print("Enemy Attack Successful! Player HP is now: {PlayerHealth}")
else if(EnemyDiceResult = PlayerDiceResult):
set PlayerHealth -= 1
Print("Roll was a tie. Player lost 1 HP")
else:
Print("The Enemy missed!")
# Only let enemy attack player if player has more than 50 health
# 全ての条件が成功すればthenのコードが実行される
if:
EnemyDiceResult > PlayerDiceResult
PlayerHealth > 50
then:
set PlayerHealth -= EnemyAttackDamage
else:
Print("The Enemy missed!")
# if文の別の書き方
# :がない
if(EnemyDiceResult > PlayerDiceResult) { Print("Enemy is Attacking")}
https://www.youtube.com/watch?v=JVnHAKbPowo
・loop, break
・Ctrl+/で選択した行をコメントアウトできる
・ループ内でPrintが多いと最後のPrintが表示されない。ループ内のPrintをコメントアウトして対応
・for
・Shift+Tabでインデントを減らす
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/Random }#GetRandomIntのために必要
# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.
# A Verse-authored creative device that can be placed in a level
Lesson_04 := class(creative_device):
var PlayerHealth : int = 100
var EnemyHealth : int = 100
var AttackDamage : int = 11
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
var Iteration : int = 0
loop:
set Iteration += 1
Print("Loop Iteration: {Iteration}")
var PlayerDiceResult : int = GetRandomInt(1, 20)
var EnemyDiceResult : int = GetRandomInt(1, 20)
# Print("Player Dice: {PlayerDiceResult}")
# Print("Enemy Dice: {EnemyDiceResult}")
if(EnemyDiceResult > PlayerDiceResult):
set PlayerHealth -= AttackDamage
# Print("Enemy Attack Successful!")
else if(EnemyDiceResult = PlayerDiceResult):
set PlayerHealth -= 1
# Print("Roll was a tie. Player lost 1 HP")
else:
set EnemyHealth -= AttackDamage
# Print("Player Attack Successful!")
if(PlayerHealth <= 0):
Print("Player died")
break
else if(EnemyHealth <= 0):
Print("Enemy died")
break
Print("The game has ended")
# var IDX : int = 0
# loop:
# if (IDX >= 10):
# break
# set IDX += 1
for(X : int = 1..10):
Print("Index: {X}")
https://www.youtube.com/watch?v=1n5BqEaLpPM
・関数の作成
・voidは空の意味。何も返さない関数に使う
・voidの部分はlogicやintなどに変えると、戻り値の型を制定できる
・logicはC++でのbool。trueとfalse
・型の宣言は省略できる。
IsBattleInProgressの戻り値がlogicなのでFightingもlogicだと推測できる。
Fighting := IsBattleInProgress()
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/Random }#GetRandomIntのために必要
# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.
# A Verse-authored creative device that can be placed in a level
Lesson_05 := class(creative_device):
var EnemyHP : int = 100
var PlayerHP : int = 100
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
StartGame()
StartGame() : void=
loop:
AttackEnemy()
EnemyAttackPlayer()
Fighting := IsBattleInProgress()
if(Fighting = false){ break }
set PlayerHP += GenerateRandomHealthPotion()
AttackEnemy() : void=
set EnemyHP -= GetRandomInt(1,10)
# Print("Enemy HP: {EnemyHP}")
EnemyAttackPlayer() : void=
set PlayerHP -= GetRandomInt(1,10)
# Print("Player HP: {PlayerHP}")
IsBattleInProgress() : logic=
if(EnemyHP <= 0):
Print("Player defeated enemy")
return false
else if(PlayerHP <= 0):
Print("The enemy has defeated player")
return false
else:
Print("The battle continues!")
return true
GenerateRandomHealthPotion() : int=
return GetRandomInt(10,50)
https://www.youtube.com/watch?v=54x43SXNPhI
・AimTrainerというプロジェクトを作成。
・@editableをつけるとアンリアルエディターのエディターでその変数を公開できる。
creative_propでプロップを指定できる。
@editable var Prop : creative_prop = creative_prop{}
作ったVerseファイルでpropを選択できるようになる。
・vector3のために下記が必要。
using { /UnrealEngine.com/Temporary/SpatialMath }
・# PropをNewPositionへテレポート。ローテーションはそのまま。
# 失敗する可能性があるので赤い波線が出る。if文で囲う必要がある。これを失敗コンテキストと呼ぶ
if(Prop.TeleportTo[NewPosition, Prop.GetTransform().Rotation]){}
・ループで待機させるにはSleepを使い秒数を指定する。
Sleep(2.0)
・サスペンド修飾子を使うことで関数が単独で動く。
MoveProp()<suspends>:void=
・関数をspawn:後に呼ぶことで独立して実行する
OnBegin<override>()<suspends>:void=
spawn:
MoveProp()
・プロップマニピュレータを使うとプロップで様々な操作ができるようになる。
・ゾーン内のすべてのオブジェクトに影響を与えるには詳細設定でチェック。
・詳細設定でプロップの耐久力を調整できる。
・prop_manipulator_deviceでプロップマニピュレータを指定できる。
@editable var PropManipulator : prop_manipulator_device = prop_manipulator_device{}
・プロップのダメージイベントは下記のように使う。
ダメージを受けるたびにMoveProp関数を実行する。
OnBegin<override>()<suspends>:void=
PropManipulator.DamagedEvent.Subscribe(OnPropDamaged)
MoveProp()
OnPropDamaged(Agent: agent):void=
MoveProp()
・武器を使うにはアイテムスポナーがいる。
・アイテムスポナーのアイテムリストで武器を選択できる。
・シミュレーションの経過時間を取得するには下記のように書く。
set TimeStap = GetSimulationElapsedTime()
・Deviceのビルボードでテキストを表示できる。
・billboard_deviceでビルボードを指定できる。
@editable var ScoreBillboard : billboard_device = billboard_device{}
・ビルボードにセットするテキストは次のように宣言している。
ScoreText<localizes>(ScoreMessage : string): message = "Score: {ScoreMessage}"
・ビルボードにはSetText関数がある。
ScoreBillboard.SetText( ScoreText("Score: {Score}"))
・アイテムスポナーはitem_spawner_deviceで指定。
@editable var WeaponSpawner : item_spawner_device = item_spawner_device{}
・アイテムスポナーのItemPickedUpEventは次のように使う。
OnBegin<override>()<suspends>:void=
PropManipulator.DamagedEvent.Subscribe(OnPropDamaged)
WeaponSpawner.ItemPickedUpEvent.Subscribe(OnWeaponPickedUp)
ScoreBillboard.SetText( ScoreText("Score: {Score}"))
OnWeaponPickedUp(Agent: agent):void=
ShowNextTarget()
・ゲームを終了するにはend_game_deviceが必要。
勝利スコアをエディタで編集できるようにしている。
@editable var EndGameDevice : end_game_device = end_game_device{}
@editable var WinScore : float = 50.0
・勝利条件を満たせばプレイヤーを取得してゲームを終了。
if(Score >= WinScore):
# 全てのプレイヤーを取得。
AllPlayers := GetPlayspace().GetPlayers()
for(Player : AllPlayers):
# PlayerはAgentなのでキャストできる。
if(Agent := agent[Player]):
EndGameDevice.Activate(Agent)
・Deviceのエンドゲームデバイスを設置する必要がある。
・Sleepには<suspends>が必要。
ShowNextTarget(Delay : float)<suspends>:void=
Sleep(Delay)
・Sleepを使っている関数を呼び出すにはspawnが必要。
OnWeaponPickedUp(Agent: agent):void=
spawn:
ShowNextTarget(3.0)
OnPropDamaged(Agent: agent):void=
UpdateScore()
spawn:
ShowNextTarget(1.0)
・プロップの表示と非表示は下記。
PropManipulator.HideProps()
PropManipulator.ShowProps()
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }#for vector3
# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.
# A Verse-authored creative device that can be placed in a level
aim_trainer := class(creative_device):
# @editableをつけるとアンリアルエディターのエディターでその変数を公開できる。
@editable var Prop : creative_prop = creative_prop{}
@editable var MinimumPositions : vector3 = vector3{}
@editable var MaximumPositions : vector3 = vector3{}
@editable var PropManipulator : prop_manipulator_device = prop_manipulator_device{}
@editable var ScoreBillboard : billboard_device = billboard_device{}
@editable var WeaponSpawner : item_spawner_device = item_spawner_device{}
@editable var EndGameDevice : end_game_device = end_game_device{}
@editable var WinScore : float = 50.0
ScoreText<localizes>(ScoreMessage : string): message = "Score: {ScoreMessage}"
var TimeStamp : float = 0.0
var Score : float = 0.0
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
PropManipulator.DamagedEvent.Subscribe(OnPropDamaged)
WeaponSpawner.ItemPickedUpEvent.Subscribe(OnWeaponPickedUp)
ScoreBillboard.SetText( ScoreText("Score: {Score}"))
OnWeaponPickedUp(Agent: agent):void=
spawn:
ShowNextTarget(3.0)
OnPropDamaged(Agent: agent):void=
PropManipulator.HideProps()
UpdateScore()
spawn:
ShowNextTarget(1.0)
UpdateScore():void=
CurrentTimestamp := GetSimulationElapsedTime()
AttackSpeed := CurrentTimestamp - TimeStamp
var EarnedPoints : float = 1.0
if(AttackSpeed <= 1.0):
set EarnedPoints = 10.0
else if(AttackSpeed <= 2.0):
set EarnedPoints = 5.0
else if(AttackSpeed <= 3.0):
set EarnedPoints = 3.0
else if(AttackSpeed >= 5.0):
set EarnedPoints = 0.0
set Score += EarnedPoints
ScoreBillboard.SetText( ScoreText("Score: {Score}"))
if(Score >= WinScore):
# 全てのプレイヤーを取得。
AllPlayers := GetPlayspace().GetPlayers()
for(Player : AllPlayers):
# PlayerはAgentなのでキャストできる。
if(Agent := agent[Player]):
EndGameDevice.Activate(Agent)
ShowNextTarget(Delay : float)<suspends>:void=
Sleep(Delay)
RandX := GetRandomFloat(MinimumPositions.X, MaximumPositions.X)
RandY := GetRandomFloat(MinimumPositions.Y, MaximumPositions.Y)
RandZ := GetRandomFloat(MinimumPositions.Z, MaximumPositions.Z)
NewPosition := vector3{X := RandX, Y := RandY, Z := RandZ}
# PropをNewPositionへテレポート。ローテーションはそのまま。
# 失敗する可能性があるので赤い波線が出る。if文で囲う必要がある。これを失敗コンテキストと呼ぶ
if(Prop.TeleportTo[NewPosition, Prop.GetTransform().Rotation]){}
PropManipulator.ShowProps()
set TimeStamp = GetSimulationElapsedTime()
AimTrainer/Lesson_07で実行。
# 配列は型の前に[]が必要。
Roasts : []string = array{"0", "1", "2", "3"}
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
# 存在しないインデックスにアクセスする可能性があるのでif文を使う。
if(RandomRoast := Roasts[0]):
Print(RandomRoast)
# 存在しないインデックスを試す。
if(ForthElement := Roasts[3]):
Print(ForthElement)
この場合前者しか表示されない。
# 配列の最後のインデックスにアクセスする。
# Lengthで配列の長さを取得している。配列は0から始まるので1引く必要がある。
if(LastItem := Roasts[Roasts.Length - 1]):
Print(LastItem)
# 変数配列も作成。
var Boasts : []string = array{"0/", "1/", "2/"}
# 配列にセットする場合にもif文が必要。
if(set Boasts[0] = "New 0!"){}
# 配列に要素を追加。
set Boasts += array{"love it", "You", "ooo"}
if(ForthElement := Boasts[3]):
Print(ForthElement)
# 配列のfor文。
for(Word : Boasts):
Print(Word)
#別の書き方。
for(Index := 0..Roasts.Length - 1):
if(Roast := Roasts[Index]):
Print("{Roast}")
#多次元配列
# ?をつけているのは失敗する可能性があるから。
var TileGrid : [][]?creative_prop = array{array{}}
# TileAssetにDefaultCreativePropAssetを指定かつエディタブルにする。
@editable var TileAsset : creative_prop_asset := DefaultCreativePropAsset
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
GenerateTiles()
# CreateTileForIndexを実行する関数。
GenerateTiles():void=
set TileGrid =
for(Row := 0..5):
for(Column := 0..5):
CreateTileForIndex(Row, Column)
# タイルを生成する関数。
CreateTileForIndex(XIdx : int, YIdx : int) : ?creative_prop=
# タイルを配置する間隔。
Spacer := 700.0
if(XPos := float[XIdx * Spacer], YPos := float[YIdx * Spacer]):
# IdentityRotationはデフォルトのローテーション。
SpawnPropTuple := SpawnProp(TileAsset, vector3{X := XPos, Y := YPos, Z := 10.0}, IdentityRotation())
return SpawnPropTuple(0)
# スポーンが失敗したときのために必要。
else:
return false
ランダムにタイルを削除
# ランダムにタイルを削除
RemoveRandomTiles():void=
if(NumberOfColumns : int = TileGrid[0].Length):
for(Row := 0..TileGrid.Length - 1, Column := 0..NumberOfColumns):
if(Tile := TileGrid[Row][Column]?):
Rand := GetRandomInt(0, 1)
if(Rand = 0):
# Randが0の場合TileをRemove
Tile.Dispose()
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Verse.org/Random }
Lesson_07 := class(creative_device):
# 配列は型の前に[]が必要。
Roasts : []string = array{"0", "1", "2"}
# 変数配列も作成。
var Boasts : []string = array{"0/", "1/", "2/"}
#多次元配列
# ?をつけているのは失敗する可能性があるから。
var TileGrid : [][]?creative_prop = array{array{}}
# TileAssetにDefaultCreativePropAssetを指定かつエディタブルにする。
@editable var TileAsset : creative_prop_asset := DefaultCreativePropAsset
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
GenerateTiles()
Sleep(5.0)
RemoveRandomTiles()
# 存在しないインデックスにアクセスする可能性があるのでif文を使う。
if(RandomRoast := Roasts[0]):
Print(RandomRoast)
# 存在しないインデックスを試す。
if(ForthElement := Roasts[3]):
Print(ForthElement)
# 配列の最後のインデックスにアクセスする。
# Lengthで配列の長さを取得している。配列は0から始まるので1引く必要がある。
if(LastItem := Roasts[Roasts.Length - 1]):
Print(LastItem)
# 配列にセットする場合にもif文が必要。
if(set Boasts[0] = "New 0!"){}
# 配列に要素を追加。
set Boasts += array{"love it", "You", "ooo"}
if(ForthElement := Boasts[3]):
Print(ForthElement)
# 配列のfor文。
for(Word : Boasts):
Print(Word)
#別の書き方。
for(Index := 0..Roasts.Length - 1):
if(Roast := Roasts[Index]):
Print("{Roast}")
# CreateTileForIndexを実行する関数。
GenerateTiles():void=
set TileGrid =
for(Row := 0..5):
for(Column := 0..5):
CreateTileForIndex(Row, Column)
# タイルを生成する関数。
CreateTileForIndex(XIdx : int, YIdx : int) : ?creative_prop=
# タイルを配置する間隔。
Spacer := 700.0
if(XPos := float[XIdx * Spacer], YPos := float[YIdx * Spacer]):
# IdentityRotationはデフォルトのローテーション。
SpawnPropTuple := SpawnProp(TileAsset, vector3{X := XPos, Y := YPos, Z := 10.0}, IdentityRotation())
return SpawnPropTuple(0)
# スポーンが失敗したときのために必要。
else:
return false
# ランダムにタイルを削除
RemoveRandomTiles():void=
if(NumberOfColumns : int = TileGrid[0].Length):
for(Row := 0..TileGrid.Length - 1, Column := 0..NumberOfColumns):
if(Tile := TileGrid[Row][Column]?):
Rand := GetRandomInt(0, 1)
if(Rand = 0):
# Randが0の場合TileをRemove
Tile.Dispose()
https://www.youtube.com/watch?v=gf7GulPbOEY
AimTrainer/Lesson_08で実行。
# pawn_classを作成。
pawn := class():
var TotalHP : int = 100
var CurrentHP : int = 100
TakeDamage(DamaePoints : int):void=
set CurrentHP -= DamaePoints
Heal(HealPoints : int):void=
set CurrentHP += HealPoints
# <decides>をつけることで生きていない場合失敗できるようにする。
IsAlive()<decides>:void=
if(CurrentHP > 0){true}
else{false}
Lesson_08 := class(creative_device):
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
SomePawn := pawn{}
SomePawn.TakeDamage(10)
# pawn_classを継承。
platform := class(pawn):
PlatformProp : creative_prop = creative_prop{}
StartingPos : vector3 = vector3{}
EndingPos : vector3 = vector3{}
Lesson_08 := class(creative_device):
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
SomePawn := pawn{}
SomePawn.TakeDamage(10)
NewPlatform := platform{}
NewPlatform.TakeDamage(10)
# <private>をつけて変数の操作を制限することで、バグを減らす。
var TotalHP<private> : int = 100
var CurrentHP<private> : int = 100
# <public>をつけることで関数を公開する。
TakeDamage<public>(DamaePoints : int):void=
set CurrentHP -= DamaePoints
Heal<public>(HealPoints : int):void=
set CurrentHP += HealPoints
# <decides>をつけることで生きていない場合失敗できるようにする。
IsAlive<public>()<decides>:void=
if(CurrentHP > 0){true}
else{false}
Move<public>()<suspends>:void=
loop:
# PlatformPropが有効でなければBreak
if(not PlatformProp.IsValid[]){break}
# 有効ならMoveTo
PlatformProp.MoveTo(EndingPos, IdentityRotation(),5.0)
if(not PlatformProp.IsValid[]){break}
PlatformProp.MoveTo(StartingPos, IdentityRotation(),5.0)
Lesson_08 := class(creative_device):
@ editable PlatformAsset : creative_prop_asset = DefaultCreativePropAsset
var Platforms : []platform = array{}
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
SomePawn := pawn{}
SomePawn.TakeDamage(10)
NewPlatform := platform{}
NewPlatform.TakeDamage(10)
InitPlatforms()
InitPlatforms():void=
for(IDX := 1..20):
Start := vector3{X:=IDX*500.0, Y:= IDX*500.0,Z:= 300.0}
End := vector3{X:=IDX*3000.0, Y:= IDX*3000.0,Z:= 300.0}
if(SpawnedProp := SpawnProp(PlatformAsset,Start,IdentityRotation())(0)?):
Platform := platform{PlatformProp := SpawnedProp,StartingPos := Start, EndingPos := End}
set Platforms += array{Platform}
InitPlatforms()
MoveAllPlatforms()
MoveAllPlatforms():void=
for(Platform : Platforms):
# spawn:を買うと関数を一時停止できる。
spawn:
Platform.Move()
# pawn_classを継承したpet_classの作成。
# クラスに concrete 指定子がある場合、 cat{} などの空のアーキタイプでクラスを作成できます。
pet := class<concrete>(pawn):
Name :string = "Deault"
@editable RoboProp : creative_prop = creative_prop{}
@editable RunAnim : cinematic_sequence_device = cinematic_sequence_device{}
@editable JumpAnim : cinematic_sequence_device = cinematic_sequence_device{}
@editable DamageVol : damage_volume_device = damage_volume_device{}
MoveToPlayer():void=
block:
Run():void=
RunAnim.Play()
Jump():void=
JumpAnim.Play()
Lesson_08 := class(creative_device):
@editable Robots : []pet = array{}
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.
# pawn_classを作成。
pawn := class():
# <private>をつけて変数の操作を制限することで、バグを減らす。
var TotalHP<private> : int = 100
var CurrentHP<private> : int = 100
# <public>をつけることで関数を公開する。
TakeDamage<public>(DamaePoints : int):void=
set CurrentHP -= DamaePoints
Heal<public>(HealPoints : int):void=
set CurrentHP += HealPoints
# <decides>をつけることで生きていない場合失敗できるようにする。
IsAlive<public>()<decides>:void=
if(CurrentHP > 0){true}
else{false}
# pawn_classを継承。
platform := class(pawn):
PlatformProp : creative_prop = creative_prop{}
StartingPos : vector3 = vector3{}
EndingPos : vector3 = vector3{}
Move<public>()<suspends>:void=
loop:
# PlatformPropが有効でなければBreak
if(not PlatformProp.IsValid[]){break}
# 有効ならMoveTo
PlatformProp.MoveTo(EndingPos, IdentityRotation(),5.0)
if(not PlatformProp.IsValid[]){break}
PlatformProp.MoveTo(StartingPos, IdentityRotation(),5.0)
# pawn_classを継承したpet_classの作成。
# クラスに concrete 指定子がある場合、 cat{} などの空のアーキタイプでクラスを作成できます。
pet := class<concrete>(pawn):
Name :string = "Deault"
@editable RoboProp : creative_prop = creative_prop{}
@editable RunAnim : cinematic_sequence_device = cinematic_sequence_device{}
@editable JumpAnim : cinematic_sequence_device = cinematic_sequence_device{}
@editable DamageVol : damage_volume_device = damage_volume_device{}
MoveToPlayer():void=
block:
Run():void=
RunAnim.Play()
Jump():void=
JumpAnim.Play()
Lesson_08 := class(creative_device):
@editable PlatformAsset : creative_prop_asset = DefaultCreativePropAsset
var Platforms : []platform = array{}
@editable Robots : []pet = array{}
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
SomePawn := pawn{}
SomePawn.TakeDamage(10)
NewPlatform := platform{}
NewPlatform.TakeDamage(10)
InitPlatforms()
MoveAllPlatforms()
# petクラスのRobotを作成。
Robot := pet{Name:="Larry"}
InitPlatforms():void=
for(IDX := 1..20):
Start := vector3{X:=IDX*500.0, Y:= IDX*500.0,Z:= 300.0}
End := vector3{X:=IDX*3000.0, Y:= IDX*3000.0,Z:= 300.0}
if(SpawnedProp := SpawnProp(PlatformAsset,Start,IdentityRotation())(0)?):
Platform := platform{PlatformProp := SpawnedProp,StartingPos := Start, EndingPos := End}
set Platforms += array{Platform}
MoveAllPlatforms():void=
for(Platform : Platforms):
# spawn:を買うと関数を一時停止できる。
spawn:
Platform.Move()