USER TYPE ISSUE

General FreeBASIC programming questions.
MystikShadows
Posts: 612
Joined: Jun 15, 2005 13:22
Location: Upstate NY
Contact:

USER TYPE ISSUE

Postby MystikShadows » Sep 09, 2020 19:51

In case it might help Ship data is a TYPE/END TYPE structure declared in a separate module.
I declare these two in fhe sane sub name.

Code: Select all

DIM WorkShip    AS ShipData
REDIM PRESERVE FleetShips(460)    AS ShipData
 


REDIM PRESERVE cause I have FleetShips earlier as a DIM SHARED FleetShips() as ShipData

it's not recognizing Shipdata but only for workShip. as in in the editor if I type WorkShip. no subfields appear there is no autocomplete. but if I type fleetships(1). then all the fields are in the auto complete list, as if it doesn't give WorkShip the right Structure.

EDIT:just cause i did it lol, I also tried declaring WorkShip as dim shared erlier and not declaring it the sub. same results.
Imortis
Moderator
Posts: 1729
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: USER TYPE ISSUE

Postby Imortis » Sep 10, 2020 13:43

What is the editor? I have found that with a couple of the newer ones, you have to save the file, close it and re-open it before those kinds of auto-completes will work.
MystikShadows
Posts: 612
Joined: Jun 15, 2005 13:22
Location: Upstate NY
Contact:

Re: USER TYPE ISSUE

Postby MystikShadows » Sep 10, 2020 14:19

winFBE Version 2.1.7 which i believe is the last version available.

Bot only does it not save the type to update the autocomplete, but it does give it the type either during compilation. The executable doesn't work either.though it compiles without any warning or issue with the type. just seems to skip over that and have the error when I execute it.
MrSwiss
Posts: 3610
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: USER TYPE ISSUE

Postby MrSwiss » Sep 10, 2020 14:44

Sorry, but the supplied information is just to skimpy (not enough) to make sense.
All those type definitions are currently unknown ... ctor/dtor/operators e.t.c.
MystikShadows
Posts: 612
Joined: Jun 15, 2005 13:22
Location: Upstate NY
Contact:

Re: USER TYPE ISSUE

Postby MystikShadows » Sep 10, 2020 15:17

in typemodule.bi i have :

Code: Select all

TYPE ShipData
     ShipID                       AS long
     ShipTypeID                   as Long
     ShipClassID                  As Long
     ShipCallSign                 AS String * 40
     UAPShipRegistryNumber        AS String * 20
     Location                     AS AstrometricPosition
     Position                     As SensoryPosition
     ShipWidth                    As Double
     ShipHeight                   AS Double
     ShipDepth                    AS Double
     ShipWeight                   As Double
     DeckCount                    As Long
     SectionCount                 AS Long
     CruiseSpeed                  AS DOUBLE
     MaximumSpeed                 AS DOUBLE
     EmergencySpeed               AS DOUBLE
     Communications               As Double
     HullIntegrity                As Double
     Computer                     As Double
     Transporters                 AS Double
     LifeSupport                  As Double
     AuxilliaryLifeSupport        As Double
     MedicalBays                  As Double
     MedicalBedConsoles           aS Double 
     PrimaryWeaponName            As String * 40
     PrimaryWeapon                AS Double
     SecondaryWeaponName          As String * 40
     SecondaryWeapon              AS Double
     PrimaryDefenseName           AS String * 40
     PrimaryDefense               as double
     SecondaryDefenseName         AS String * 40
     SecondaryDefense             as double
     CloakingSystem               as Double
     CurrentCrew                  as Double
     MaximumCrew                  As Double
     Probes                       as Double
     Decoys                       as Double
     ShuttleBays                  As Double
     Shuttles                     AS Double
     Supplies                     AS Double
     Torpedoes                    As Double
     Defenses                     As Double
     Weapons                      As Double
     MedicalSupplies              As Double
     Naterials                    As Double                     
     IsDestroyed                  AS Byte
     IsDisabled                   As Byte
ENd TYPE


in initializemodule.bi at the top of the module i have

EDIT: Sorry it used to be fleetsships but it never was in the module itself. simple typoe.

Code: Select all

DIM SHARED FleetShips() as ShipData


in the same module i have a sub

Code: Select all

SUB ReadFleetShips()

    DIM Counter     AS LONG
    DIM ShipCount   AS LONG
    DIM WorkCount   AS LONG
    DIM ArrayOffset AS LONG
    DIM WorkShip    AS ShipData
   
    REDIM PRESERVE FleetShips(460)    AS ShipData

    ArrayOffset = 0
    FOR Counter = 1 TO 10
        READ WorkShip.ShipID
        READ WorkShip.ShipTypeID
        READ WorkShip.ShipClassID
        Read WorkShip.ShipCallSign
        READ WorkShip.UAPShipRegistryNumber
        READ ShipCount
        READ WorkShip.ShipHeight
        READ WorkShip.ShipWidth
        READ WorkShip.ShipDepth
        Read WorkShip.ShipWeight
        Read WorkShip.DeckCount
        Read WorkShip.SectionCount
        Read WorkShip.CruiseSpeed
        Read WorkShip.MaximumSpeed
        Read WorkShip.EmergencySpeed
        Read WorkShip.Communications
        Read WorkShip.HullIntegrity
        Read WorkShip.Computer
        Read WorkShip.Transporters
        Read WorkShip.LifeSupport
        Read WorkShip.AuxilliaryLifeSupport
        Read WorkShip.MedicalBays
        Read WorkShip.PrimaryWeaponName
        Read WorkShip.PrimaryWeapon
        Read WorkShip.SecondaryWeaponName
        Read WorkShip.SecondaryWeapon
        Read WorkShip.PrimaryDefenseName
        Read WorkShip.PrimaryDefense
        Read WorkShip.SecondaryDefenseName
        Read WorkShip.SecondaryDefense
        Read WorkShip.CloakingSystem           
        Read WorkShip.CurrentCrew             
        Read WorkShip.MaximumCrew                 
        Read WorkShip.Probes                           
        Read WorkShip.Decoys                       
        Read WorkShip.ShuttleBays                 
        Read WorkShip.Shuttles                     
        Read WorkShip.Supplies                     
        Read WorkShip.Torpedoes                   
        Read WorkShip.Defenses                     
        Read WorkShip.Weapons                       
        Read WorkShip.MedicalSupplies             
        Read WorkShip.Naterials                   
        Read WorkShip.IsDisabled
        Read WorkShip.IsDestroyed
        FOR WorkCount = 0 TO ShipCount - 1
            WorkShip.ShipID = ArrayOffset + WorkCount
            FleetShips(ArrayOffset + WorkCount) = WorkShip
        NEXT WorkCount
        ArrayOffset = ArrayOffset + ShipCount
    NEXT Counter

END SUB


you see all these WorkShip Attributes? then don't seem to exist because the editor isnt populating the autocomplete list and this FleetShips(ArrayOffset + WorkCount) = WorkShip has a conversion error meaning its not a ShipData but it is as you can see in the start of the sub. it is declared as ShipData. but somehow its not of shipdata type it looses its type or is never given the type shipdata in the first place. the fleetship array is fine but workship isn't.
Last edited by MystikShadows on Sep 10, 2020 15:31, edited 2 times in total.
Xusinboy Bekchanov
Posts: 254
Joined: Jul 26, 2018 18:28

Re: USER TYPE ISSUE

Postby Xusinboy Bekchanov » Sep 10, 2020 15:25

FleetSShips and FleetShips are different.
MystikShadows
Posts: 612
Joined: Jun 15, 2005 13:22
Location: Upstate NY
Contact:

Re: USER TYPE ISSUE

Postby MystikShadows » Sep 10, 2020 15:33

Xusinboy Bekchanov wrote:FleetSShips and FleetShips are different.


Sorry me and my 2x4s i call my fingers are typing all kinds of hell. lol

for the heck of it I opened it up in FBEDIT I can see the autocomplete shows me the items fine for workShip but still the same error occurs. somehow I can't assign workship to fleetships(n)
Last edited by MystikShadows on Sep 10, 2020 15:42, edited 1 time in total.
fxm
Posts: 9946
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: USER TYPE ISSUE

Postby fxm » Sep 10, 2020 15:38

When resizing an array (already declared), declaring its type again in the syntax is unnecessary, and I would even say it is useful not to re-declare its type in order to verify that there is no typo on the name of the array.
MrSwiss
Posts: 3610
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: USER TYPE ISSUE

Postby MrSwiss » Sep 10, 2020 15:42

If you are having type definition in a .bi and type initialization in another .bi then
the order in which the .bi's are included becomes important (otherwise error).

I don't understand the 'Editor claim' with 'autocomplete' at all.
You have to supply the code that initializes the type (or type array).

BTW: arrays in FB are 0 based so, if you want to make them 1 based you'll have to explicitly state that:

Code: Select all

REDIM PRESERVE FleetShips(460)   '' nope = 461 elements
REDIM PRESERVE FleetShips(1 TO 460)   '' correct = 460 elements
fxm
Posts: 9946
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: USER TYPE ISSUE

Postby fxm » Sep 10, 2020 15:46

fxm wrote:When resizing an array (already declared), declaring its type again in the syntax is unnecessary, and I would even say it is useful not to re-declare its type in order to verify that there is no typo on the name of the array.

Code: Select all

Dim As Integer array1()
Redim As Integer aray1(10)  '' no error and another new array is declared

Dim As Integer array2()
Redim aray2(10)             '' error
Imortis
Moderator
Posts: 1729
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: USER TYPE ISSUE

Postby Imortis » Sep 10, 2020 17:42

I took your code, made a few code modification to make it do something without all the extra info, and moved it all to one file for ease of testing and it seems to work just fine.

Code: Select all

TYPE ShipData
     ShipID                       AS long
     ShipTypeID                   as Long
     ShipClassID                  As Long
     ShipCallSign                 AS String * 40
     UAPShipRegistryNumber        AS String * 20
     'Location                     AS AstrometricPosition
     'Position                     As SensoryPosition
     ShipWidth                    As Double
     ShipHeight                   AS Double
     ShipDepth                    AS Double
     ShipWeight                   As Double
     DeckCount                    As Long
     SectionCount                 AS Long
     CruiseSpeed                  AS DOUBLE
     MaximumSpeed                 AS DOUBLE
     EmergencySpeed               AS DOUBLE
     Communications               As Double
     HullIntegrity                As Double
     Computer                     As Double
     Transporters                 AS Double
     LifeSupport                  As Double
     AuxilliaryLifeSupport        As Double
     MedicalBays                  As Double
     MedicalBedConsoles           aS Double
     PrimaryWeaponName            As String * 40
     PrimaryWeapon                AS Double
     SecondaryWeaponName          As String * 40
     SecondaryWeapon              AS Double
     PrimaryDefenseName           AS String * 40
     PrimaryDefense               as double
     SecondaryDefenseName         AS String * 40
     SecondaryDefense             as double
     CloakingSystem               as Double
     CurrentCrew                  as Double
     MaximumCrew                  As Double
     Probes                       as Double
     Decoys                       as Double
     ShuttleBays                  As Double
     Shuttles                     AS Double
     Supplies                     AS Double
     Torpedoes                    As Double
     Defenses                     As Double
     Weapons                      As Double
     MedicalSupplies              As Double
     Naterials                    As Double                     
     IsDestroyed                  AS Byte
     IsDisabled                   As Byte
ENd TYPE

DIM SHARED FleetShips() as ShipData

SUB ReadFleetShips()

    DIM Counter     AS LONG
    DIM ShipCount   AS LONG
    DIM WorkCount   AS LONG
    DIM ArrayOffset AS LONG
    DIM WorkShip    AS ShipData
   
    REDIM PRESERVE FleetShips(460)    AS ShipData
    ArrayOffset = 0
    FOR Counter = 1 TO 10
        READ WorkShip.ShipID
        READ WorkShip.ShipTypeID
        READ WorkShip.ShipClassID
        Read WorkShip.ShipCallSign
        READ WorkShip.UAPShipRegistryNumber
        READ ShipCount
        READ WorkShip.ShipHeight
        READ WorkShip.ShipWidth
        READ WorkShip.ShipDepth
        Read WorkShip.ShipWeight
        Read WorkShip.DeckCount
        Read WorkShip.SectionCount
        Read WorkShip.CruiseSpeed
        Read WorkShip.MaximumSpeed
        Read WorkShip.EmergencySpeed
        Read WorkShip.Communications
        Read WorkShip.HullIntegrity
        Read WorkShip.Computer
        Read WorkShip.Transporters
        Read WorkShip.LifeSupport
        Read WorkShip.AuxilliaryLifeSupport
        Read WorkShip.MedicalBays
        Read WorkShip.PrimaryWeaponName
        Read WorkShip.PrimaryWeapon
        Read WorkShip.SecondaryWeaponName
        Read WorkShip.SecondaryWeapon
        Read WorkShip.PrimaryDefenseName
        Read WorkShip.PrimaryDefense
        Read WorkShip.SecondaryDefenseName
        Read WorkShip.SecondaryDefense
        Read WorkShip.CloakingSystem           
        Read WorkShip.CurrentCrew             
        Read WorkShip.MaximumCrew                 
        Read WorkShip.Probes                           
        Read WorkShip.Decoys                       
        Read WorkShip.ShuttleBays                 
        Read WorkShip.Shuttles                     
        Read WorkShip.Supplies                     
        Read WorkShip.Torpedoes                   
        Read WorkShip.Defenses                     
        Read WorkShip.Weapons                       
        Read WorkShip.MedicalSupplies             
        Read WorkShip.Naterials                   
        Read WorkShip.IsDisabled
        Read WorkShip.IsDestroyed
        FOR WorkCount = 0 TO ShipCount - 1
            WorkShip.ShipID = ArrayOffset + WorkCount
            FleetShips(ArrayOffset + WorkCount) = WorkShip
        NEXT WorkCount
        ArrayOffset = ArrayOffset + ShipCount
    NEXT Counter

END SUB

Data 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,"X",1,"X",1,"X",1,"X",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,"X",1,"X",1,"X",1,"X",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,"X",1,"X",1,"X",1,"X",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,"X",1,"X",1,"X",1,"X",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,"X",1,"X",1,"X",1,"X",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 5,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,"X",1,"X",1,"X",1,"X",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 6,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,"X",1,"X",1,"X",1,"X",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,"X",1,"X",1,"X",1,"X",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 8,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,"X",1,"X",1,"X",1,"X",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 9,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,"X",1,"X",1,"X",1,"X",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1

ReadFleetShips()
for i as integer = 0 to 460
   if FleetShips(i).shipTypeID <> 0 then
      print FleetShips(i).shipID, FleetShips(i).shipTypeID
   end if
next

sleep


My guess is there is something else here, or the typo mentioned above.
fxm
Posts: 9946
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: USER TYPE ISSUE

Postby fxm » Sep 10, 2020 18:40

Imortis wrote:I took your code, made a few code modification to make it do something without all the extra info, and moved it all to one file for ease of testing and it seems to work just fine.
.....
REDIM PRESERVE FleetShips(460) AS ShipData
.....

I see that my advice (and also the syntax specified in the REDIM documentation) is not applied, but everyone is still free to code as they want at their own risk!
Imortis
Moderator
Posts: 1729
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: USER TYPE ISSUE

Postby Imortis » Sep 10, 2020 18:46

fxm wrote:
Imortis wrote:I took your code, made a few code modification to make it do something without all the extra info, and moved it all to one file for ease of testing and it seems to work just fine.
.....
REDIM PRESERVE FleetShips(460) AS ShipData
.....

I see that my advice (and also the syntax specified in the REDIM documentation) is not applied, but everyone is still free to code as they want at their own risk!


I was not ignoring your advice. I was just taking the code as presented with as little change as possible. When I do my own code, I actually do leave out the type on the redim for exactly the reason you expressed.

Return to “General”

Who is online

Users browsing this forum: No registered users and 4 guests