Page 1 of 1

Short IF statement must be on a single line!

Posted: Wed May 17, 2023 12:44 am
by phoenixkonsole
Here I am getting an error:

Short IF statement must be on a single line!
File: GAIA-X-sphere.HWS (current line: 42)

What is long and what is short : )

; Partikelsystem für die rotierende Sphere
Local particles = {} ; Array für die Partikel
Local numParticles = 100 ; Anzahl der Partikel
Local particleSpeed = 5 ; Geschwindigkeit der Partikel
Local rotationSpeed = 1 ; Geschwindigkeit der Rotation
Local particleTimer = 0 ; Timer für die Auslösung der Sonnenstürme
Local particleInterval = 5000 ; Intervall zwischen den Sonnenstürmen in Millisekunden
Local particleDuration = 1000 ; Dauer eines Sonnensturms in Millisekunden

; Funktion zum Initialisieren des Partikelsystems
Function InitParticles()
For I = 1 To numParticles
; Zufällige Startposition innerhalb der Sphere
Local angle = Rand(0, 360)
Local radius = Rand(50, 100)
Local startX = radius * Cos(angle)
Local startY = radius * Sin(angle)

; Zufällige Startgeschwindigkeit
Local speedX = Rand(-particleSpeed, particleSpeed)
Local speedY = Rand(-particleSpeed, particleSpeed)

; Partikel hinzufügen
particles = {x = startX, y = startY, dx = speedX, dy = speedY}
Next
EndFunction

; Funktion zum Aktualisieren der Partikelpositionen
Function UpdateParticles()
For I = 1 To numParticles
; Aktuelle Position und Geschwindigkeit des Partikels
Local posX = particles.x
Local posY = particles.y
Local speedX = particles.dx
Local speedY = particles.dy

; Neue Position berechnen
Local newX = posX + speedX
Local newY = posY + speedY

; Randprüfung und Umkehrung der Geschwindigkeit
If Abs(newX) > 100 Then
speedX = -speedX
EndIf

If Abs(newY) > 100 Then
speedY = -speedY
EndIf

; Neue Position und Geschwindigkeit setzen
particles.x = newX
particles.y = newY
particles.dx = speedX
particles.dy = speedY
Next
EndFunction

; Funktion zum Zeichnen der Partikel
Function DrawParticles()
For I = 1 To numParticles
; Aktuelle Position des Partikels
Local posX = particles.x
Local posY = particles[I].y

; Partikel zeichnen
Plot(posX, posY, orange)
Next
EndFunction

; Funktion zum Zeichnen der rotierenden Sphere
Function DrawSphere()
Local radius = 100 ; Radius der Sphere
Local centerX = 320 ; X-Koordinate des Zentrums
Local centerY = 240 ; Y-Koordinate des Zentrums

For angle = 0 To 360 Step 10
Local posX = centerX + radius * Cos(angle)
Local posY = centerY + radius * Sin(angle)

Plot(posX, posY, rot)
Next
EndFunction

; Funktion zum Zeichnen der Sonnenstürme
Function DrawSolarFlares()
For Each particle In particles
Local posX = particle.x
Local posY = particle.y
Local speedX = particle.dx
Local speedY = particle.dy

; Sonnenstürme auslösen
If particleTimer <= 0 Then
; Zufällige Richtung und Geschwindigkeit für den Sonnensturm
Local flareAngle = Rand(0, 360)
Local flareSpeed = Rand(2, 5)
Local flareDuration = Rand(500, 2000)

; Neue Geschwindigkeit für das Partikel setzen
particle.dx = speedX + flareSpeed * Cos(flareAngle)
particle.dy = speedY + flareSpeed * Sin(flareAngle)

; Timer und Dauer für den Sonnensturm setzen
particleTimer = particleInterval
particleDuration = flareDuration
EndIf

; Sonnensturm zeichnen
If particleTimer > 0 And particleTimer <= particleDuration Then
Plot(posX, posY, gelb)
EndIf
Next
EndFunction

; Partikelsystem initialisieren
InitParticles()

Repeat
; Hintergrund zeichnen
Background(schwarz)

; Sphere zeichnen
DrawSphere()

; Partikel aktualisieren
UpdateParticles()

; Sonnenstürme zeichnen
DrawSolarFlares()

; Partikel zeichnen
DrawParticles()

; Bild anzeigen
ShowDisplay()

; Kurze Pause
Delay(50)

; Timer für Sonnenstürme aktualisieren
particleTimer = particleTimer - 50

; Ereignisse abfangen
Until KeyHit(Key_Escape)

Re: Short IF statement must be on a single line!

Posted: Wed May 17, 2023 12:56 am
by phoenixkonsole
Ok... i tried now the following and got:

Equal sign expected!
File: GAIA-X-sphere.HWS (current line: 6)

need to read the manual :)

@DISPLAY {Width = 640, Height = 480}

; Definition der Partikelstruktur
Structure Particle
Field x, y, dx, dy
EndStructure

; Partikel-Array erstellen
Global particle[100] As Particle

; Geschwindigkeitsvektoren für die Rotation
Global rotationSpeedX = 1
Global rotationSpeedY = 1

; Funktion zum Zeichnen der Partikel
Function DrawParticles()
For I = 0 To 99
Plot(particle.x + 320, particle.y + 240, 0xFFFFFF)
Next
EndFunction

; Funktion zum Aktualisieren der Partikel
Function UpdateParticles()
For I = 0 To 99
Local newX, newY, speedX, speedY

; Geschwindigkeit des Partikels aktualisieren
speedX = particle.dx + rotationSpeedX
speedY = particle.dy + rotationSpeedY

; Neue Position berechnen
newX = particle.x + speedX
newY = particle.y + speedY

; Randprüfung und Umkehrung der Geschwindigkeit
If Abs(newX) > 100 Then speedX = -speedX
If Abs(newY) > 100 Then speedY = -speedY

; Partikel aktualisieren
particle.x = newX
particle.y = newY
particle.dx = speedX
particle.dy = speedY
Next
EndFunction

; Sonnensturm auslösen
Function TriggerSolarFlare()
; Geschwindigkeitsvektoren für Sonnensturm setzen
rotationSpeedX = Rnd(-10, 10)
rotationSpeedY = Rnd(-10, 10)

; Zufällige Partikel im Inneren der Sphäre platzieren
For I = 0 To 99
particle[I].x = Rnd(-10, 10)
particle[I].y = Rnd(-10, 10)
particle[I].dx = 0
particle[I].dy = 0
Next
EndFunction

; Initialisierung der Partikel
For I = 0 To 99
particle[I].x = Rnd(-100, 100)
particle[I].y = Rnd(-100, 100)
particle[I].dx = 0
particle[I].dy = 0
Next

Repeat
Cls

; Zeichnen der Partikel
DrawParticles()

; Aktualisieren der Partikel
UpdateParticles()

; Zufällig Sonnensturm auslösen
If Rnd(0, 100) < 1 Then TriggerSolarFlare()

Flip
Until KeyHit(KEY_ESCAPE)

Re: Short IF statement must be on a single line!

Posted: Wed May 17, 2023 8:48 am
by plouf
Correct point is to read manual :-)
Short if is the single line if statement with "then" keyword
NO "then" is necessery in long version where block of code to execute start in the next line