var<private>
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/Random }
sample_timer_device := class(creative_device):
var<private> Time:int = 0
OnBegin<override>()<suspends>:void=
loop:
# 毎秒1ずつTimeをインクリメントする
Sleep(1.0)
set Time += 1
sample_device := class(creative_device):
@editable
SampleTimerDevice:sample_timer_device = sample_timer_device{}
OnBegin<override>()<suspends>:void=
loop:
Sleep(GetRandomFloat(1.0, 5.0))
CurrentTime := SampleTimerDevice.Time
# The assignment's left hand expression type `int` cannot be assigned to(3509)
set SampleTimerDevice.Time = 100
varに対してアクセス指定子をつけてあげることで、クラス内部では値は変更できるが、外部からは定数として扱われる変数を作ることができます。
サンプルコードではsample_timer_device内では毎秒Time変数に毎秒1ずつ足す処理を書いているのですが、sample_deviceなどの外部からではThe assignment’s… と定数なので値を入れることができませんとエラーが出ます。
デフォルト
varはデフォルトでpublicとして扱われます(当然といえば当然ですが)。
そのため、
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/Random }
sample_timer_device := class(creative_device):
var Time:int = 0
OnBegin<override>()<suspends>:void=
loop:
# 毎秒1ずつTimeをインクリメントする
Sleep(1.0)
set Time += 1
sample_device := class(creative_device):
@editable
SampleTimerDevice:sample_timer_device = sample_timer_device{}
OnBegin<override>()<suspends>:void=
loop:
Sleep(GetRandomFloat(1.0, 5.0))
CurrentTime := SampleTimerDevice.Time
set SampleTimerDevice.Time = 100
とprivate指定子を外してあげると、外部のクラスから値を調整することができます。
継承
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/Random }
sample_timer_device := class(creative_device):
var<protected> Time:int = 0
OnBegin<override>()<suspends>:void=
loop:
# 毎秒1ずつTimeをインクリメントする
Sleep(1.0)
set Time += 1
sample_timer_overridable_device := class(sample_timer_device):
Override(InTime:int):void=
set Time = InTime
sample_device := class(creative_device):
@editable
SampleTimerDevice:sample_timer_overridable_device = sample_timer_overridable_device{}
OnBegin<override>()<suspends>:void=
loop:
Sleep(GetRandomFloat(1.0, 5.0))
CurrentTime := SampleTimerDevice.Time
SampleTimerDevice.Override(100)
通常のアクセス指定子と同様にprotectedでクラスの子にだけ値を変更可能かも分けることができます。
おまけ
# Used to spawn a `particle_system` at the location of this entity. The `particle_system` will simulate while the `particle_system_component` is in the scene.
#
# Dependencies:
# * `transform_component` on the entity positions the `particle_system`.
particle_system_component<native><public> := class<final_super><epic_internal>(component, enableable):
# Enables the simulation and rendering of this `particle_system`.
Enable<override><native>():void
# Disables the simulation and rendering of this `particle_system`.
Disable<override><native>():void
# Succeeds if the component is enabled, fails if it’s disabled.
IsEnabled<override><native>()<transacts><decides>:void
@editable
# Controls if the `particle_system_component` should start enabled.
var<private> Enabled<native><public>:logic = external {}
Play<native><public>():void
Stop<native><public>():void
@editable
# Controls if the `particle_system_component` should play the simulation automatically when added to the scene, or when enabled from a disabled state.
var<private> AutoPlay<native><public>:logic = external {}
公式APIでも実際に使われいる箇所がいくつもあります。これらはvarというキーワードがついているものの、privateであるため値を受け取ることしかできません。
そもそも、Verse初期のクラスではGetXXX関数とSetXXX関数がパラメータ分だけ用意されていたのですが、はやり無駄にダイジェストが長くなってしまうので変数として公開されるようになったのだと思います。