Just a simple Syntax error

Just starting out? Need help? Post your questions and find answers here.
jphoarau
Posts: 22
Joined: Thu Dec 28, 2023 4:30 am

Just a simple Syntax error

Post by jphoarau »

Hello everybody,

I'm a little ashamed to ask this question, but I'm stuck on a syntax error. It's on line 17 and I can't figure out my mistake. Can anyone unblock me?

Code: Select all

Structure Part
  part_name.s
  sound.b
  hours.b
  minuts.b
  seconds.b
EndStructure

Structure Session
  session_name.s
  Array part_Array.Part(10)
EndStructure

Global Dim part_Array.Part(10)
Global session.Session

Procedure FillPartArray(part_default.Part, snd_nbr.b, n); Here is the syntax error
  Define i = n
  
  For x = 0 To (i - 1)
    With part_default
      \part_name = "New Part " + Str(i)
      \sound = snd_nbr
      \hours = 0
      \minuts = 5
      \seconds =0
      part_Array(x) = part_default
    EndWith
  Next x
  
EndProcedure

BarJo
Posts: 5
Joined: Mon Dec 18, 2023 9:55 am

Re: Just a simple Syntax error

Post by BarJo »

Hi jphoarau,

I am still a beginner with SpiderBasic, but I would have coded it like this:

Code: Select all

Structure Part
  part_name.s
  sound.b
  hours.b
  minuts.b
  seconds.b
EndStructure

Structure Session
  session_name.s
  Array part_Array.Part(10)
EndStructure

Global Dim part_Array.Part(10)
Global session.Session

Procedure FillPartArray(List part_default.Part(), snd_nbr.b, n); Here is the syntax error
  Define i = n
  
  For x = 0 To (i - 1)
    With part_default()
      \part_name = "New Part " + Str(i)
      \sound = snd_nbr
      \hours = 0
      \minuts = 5
      \seconds =0
      part_Array(x) = part_default()
    EndWith
  Next x
  
EndProcedure
jphoarau
Posts: 22
Joined: Thu Dec 28, 2023 4:30 am

Re: Just a simple Syntax error

Post by jphoarau »

BarJo wrote: Fri Jan 19, 2024 4:39 am Hi jphoarau,

I am still a beginner with SpiderBasic, but I would have coded it like this:
Thanks for your answer. It makes me understand my mistake. A Structure can't be passed as Procedure parameter. It must be passed by pointer. I have found this with your help:

Code: Select all

Structure Part
  part_name.s
  sound.b
  hours.b
  minuts.b
  seconds.b
EndStructure

Structure Session
  session_name.s
  Array part_Array.Part(10)
EndStructure

Global Dim part_Array.Part(10)
Global session.Session
Global part_default.Part

Procedure FillPartArray(*part_temp.Part, snd_nbr.b, n); Here is the syntax error
  Define i = n
  
  For x = 0 To (i - 1)
    With *part_temp
      \part_name = "New Part " + Str(i)
      \sound = snd_nbr
      \hours = 0
      \minuts = 5
      \seconds =0
    EndWith
    part_Array(x) = part_default
  Next x
EndProcedure

FillPartArray(@part_default, 0, 3)
Many thanks.
BarJo
Posts: 5
Joined: Mon Dec 18, 2023 9:55 am

Re: Just a simple Syntax error

Post by BarJo »

jphoarau wrote: Fri Jan 19, 2024 7:25 am
BarJo wrote: Fri Jan 19, 2024 4:39 am Hi jphoarau,

I am still a beginner with SpiderBasic, but I would have coded it like this:
Thanks for your answer. It makes me understand my mistake. A Structure can't be passed as Procedure parameter. It must be passed by pointer. I have found this with your help:

Code: Select all

Structure Part
  part_name.s
  sound.b
  hours.b
  minuts.b
  seconds.b
EndStructure

Structure Session
  session_name.s
  Array part_Array.Part(10)
EndStructure

Global Dim part_Array.Part(10)
Global session.Session
Global part_default.Part

Procedure FillPartArray(*part_temp.Part, snd_nbr.b, n); Here is the syntax error
  Define i = n
  
  For x = 0 To (i - 1)
    With *part_temp
      \part_name = "New Part " + Str(i)
      \sound = snd_nbr
      \hours = 0
      \minuts = 5
      \seconds =0
    EndWith
    part_Array(x) = part_default
  Next x
EndProcedure

FillPartArray(@part_default, 0, 3)
Many thanks.

Yes, you're right, I answered too quickly.
jphoarau
Posts: 22
Joined: Thu Dec 28, 2023 4:30 am

Re: Just a simple Syntax error

Post by jphoarau »

BarJo wrote: Sun Jan 21, 2024 6:44 am Yes, you're right, I answered too quickly.
No, you helped me find the solution. Thank you.
Post Reply