Author Topic: Just what does this error mean?  (Read 3797 times)

0 Members and 1 Guest are viewing this topic.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Just what does this error mean?
« on: July 27, 2019, 05:54:16 pm »
"Unexpected internal code reference to UDT" ?

I'm guessing it means I can not do what I wish too.
but I'm still curious as to why it won't allow it, as long as the data matches up.
to do in 1 line what will take many lines otherwise would seem logical.
I can do it the long way of course, I was just hoping for a simpler, faster, and shorter one liner way when the IDE displayed that error.

Code: [Select]
TYPE Ship_Data
 Nam AS STRING * 11
 Siz AS _BYTE
 Img AS _UNSIGNED _BYTE
 Tons AS INTEGER
 Hits AS INTEGER
 Defn AS INTEGER
 Cost AS INTEGER
 Armor AS _BYTE
 Engine AS _BYTE
 Manuver AS _BYTE
 Computer AS _BYTE
 Shield AS _BYTE
 Emc AS _BYTE
 Weapon1 AS _BYTE
 Weapon2 AS _BYTE
 Weapon3 AS _BYTE
 Weapon4 AS _BYTE
 Count1 AS _BYTE
 Count2 AS _BYTE
 Count3 AS _BYTE
 Count4 AS _BYTE
 Special1 AS _BYTE
 Special2 AS _BYTE
 Special3 AS _BYTE
END TYPE

DIM SHARED Ship(5, 5) AS Ship_Data

Starting_Ships:
DATA "Scout",0,1,40,3,2,6,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0
DATA "Fighter",0,2,40,3,2,6,1,1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0
DATA "Destroyer",1,7,200,18,1,36,1,1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0
DATA "Bomber",1,8,200,18,1,36,1,1,1,0,0,0,3,0,0,0,1,0,0,0,0,0,0
DATA "Colony Ship",2,13,1000,100,0,200,1,1,1,0,0,0,0,0,0,0,0,0,0,0,2,0,0

RESTORE Starting_Ships
read ship(0,0)
Granted after becoming radioactive I only have a half-life!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Just what does this error mean?
« Reply #1 on: July 28, 2019, 04:54:38 am »
You use TYPE, so last row in your code muss be something as READ ship (0,0).nam  or  DOT something else, what you need.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Just what does this error mean?
« Reply #2 on: July 28, 2019, 09:50:38 am »
Yeah, here is your work done for you ;D
Code: QB64: [Select]
  1. TYPE Ship_Data
  2.     Nam AS STRING * 11
  3.     Siz AS INTEGER
  4.     Img AS _UNSIGNED _BYTE
  5.     Tons AS INTEGER
  6.     Hits AS INTEGER
  7.     Defn AS INTEGER
  8.     Cost AS INTEGER
  9.     Armor AS _BYTE
  10.     Engine AS _BYTE
  11.     Manuver AS _BYTE
  12.     Computer AS _BYTE
  13.     Shield AS _BYTE
  14.     Emc AS _BYTE
  15.     Weapon1 AS _BYTE
  16.     Weapon2 AS _BYTE
  17.     Weapon3 AS _BYTE
  18.     Weapon4 AS _BYTE
  19.     Count1 AS _BYTE
  20.     Count2 AS _BYTE
  21.     Count3 AS _BYTE
  22.     Count4 AS _BYTE
  23.     Special1 AS _BYTE
  24.     Special2 AS _BYTE
  25.     Special3 AS _BYTE
  26.  
  27. DIM SHARED Ship(5) AS Ship_Data
  28.  
  29. Starting_Ships:
  30. DATA "Scout      ",0,1,40,3,2,6,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0
  31. DATA "Fighter    ",0,2,40,3,2,6,1,1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0
  32. DATA "Destroyer  ",1,7,200,18,1,36,1,1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0
  33. DATA "Bomber     ",1,8,200,18,1,36,1,1,1,0,0,0,3,0,0,0,1,0,0,0,0,0,0
  34. DATA "Colony Ship",2,13,1000,100,0,200,1,1,1,0,0,0,0,0,0,0,0,0,0,0,2,0,0
  35.  
  36. RESTORE Starting_Ships
  37. FOR i = 0 TO 4
  38.     READ Ship(i).Nam
  39.     READ Ship(i).Siz
  40.     READ Ship(i).Img
  41.     READ Ship(i).Tons
  42.     READ Ship(i).Hits
  43.     READ Ship(i).Defn
  44.     READ Ship(i).Cost
  45.     READ Ship(i).Armor
  46.     READ Ship(i).Engine
  47.     READ Ship(i).Manuver
  48.     READ Ship(i).Computer
  49.     READ Ship(i).Shield
  50.     READ Ship(i).Emc
  51.     READ Ship(i).Weapon1
  52.     READ Ship(i).Weapon2
  53.     READ Ship(i).Weapon3
  54.     READ Ship(i).Weapon4
  55.     READ Ship(i).Count1
  56.     READ Ship(i).Count2
  57.     READ Ship(i).Count3
  58.     READ Ship(i).Count4
  59.     READ Ship(i).Special1
  60.     READ Ship(i).Special2
  61.     READ Ship(i).Special3
  62.     PRINT i
  63. FOR i = 0 TO 4
  64.     PRINT Ship(i).Nam, Ship(i).Cost, Ship(i).Img, Ship(i).Special1
  65.  
  66.  
  67.  

Here is test of non fixed string in Type (needs QB64 v1.3):
Code: QB64: [Select]
  1. TYPE Ship_Data
  2.     Nam AS STRING
  3.     Siz AS INTEGER
  4.     Img AS _UNSIGNED _BYTE
  5.     Tons AS INTEGER
  6.     Hits AS INTEGER
  7.     Defn AS INTEGER
  8.     Cost AS INTEGER
  9.     Armor AS _BYTE
  10.     Engine AS _BYTE
  11.     Manuver AS _BYTE
  12.     Computer AS _BYTE
  13.     Shield AS _BYTE
  14.     Emc AS _BYTE
  15.     Weapon1 AS _BYTE
  16.     Weapon2 AS _BYTE
  17.     Weapon3 AS _BYTE
  18.     Weapon4 AS _BYTE
  19.     Count1 AS _BYTE
  20.     Count2 AS _BYTE
  21.     Count3 AS _BYTE
  22.     Count4 AS _BYTE
  23.     Special1 AS _BYTE
  24.     Special2 AS _BYTE
  25.     Special3 AS _BYTE
  26.  
  27. DIM SHARED Ship(5) AS Ship_Data
  28.  
  29. Starting_Ships:
  30. DATA "Scout",0,1,40,3,2,6,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0
  31. DATA "Fighter",0,2,40,3,2,6,1,1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0
  32. DATA "Destroyer",1,7,200,18,1,36,1,1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0
  33. DATA "Bomber",1,8,200,18,1,36,1,1,1,0,0,0,3,0,0,0,1,0,0,0,0,0,0
  34. DATA "Colony Ship",2,13,1000,100,0,200,1,1,1,0,0,0,0,0,0,0,0,0,0,0,2,0,0
  35.  
  36. RESTORE Starting_Ships
  37. FOR i = 0 TO 4
  38.     READ Ship(i).Nam
  39.     READ Ship(i).Siz
  40.     READ Ship(i).Img
  41.     READ Ship(i).Tons
  42.     READ Ship(i).Hits
  43.     READ Ship(i).Defn
  44.     READ Ship(i).Cost
  45.     READ Ship(i).Armor
  46.     READ Ship(i).Engine
  47.     READ Ship(i).Manuver
  48.     READ Ship(i).Computer
  49.     READ Ship(i).Shield
  50.     READ Ship(i).Emc
  51.     READ Ship(i).Weapon1
  52.     READ Ship(i).Weapon2
  53.     READ Ship(i).Weapon3
  54.     READ Ship(i).Weapon4
  55.     READ Ship(i).Count1
  56.     READ Ship(i).Count2
  57.     READ Ship(i).Count3
  58.     READ Ship(i).Count4
  59.     READ Ship(i).Special1
  60.     READ Ship(i).Special2
  61.     READ Ship(i).Special3
  62.     PRINT i
  63. FOR i = 0 TO 4
  64.     PRINT Ship(i).Nam, Ship(i).Cost, Ship(i).Img, Ship(i).Special1

Here is a test to see if loads correctly with fixed string in type def and non fixed strings in DATA, it does!
Code: QB64: [Select]
  1. TYPE Ship_Data
  2.     Nam AS STRING * 11
  3.     Siz AS INTEGER
  4.     Img AS _UNSIGNED _BYTE
  5.     Tons AS INTEGER
  6.     Hits AS INTEGER
  7.     Defn AS INTEGER
  8.     Cost AS INTEGER
  9.     Armor AS _BYTE
  10.     Engine AS _BYTE
  11.     Manuver AS _BYTE
  12.     Computer AS _BYTE
  13.     Shield AS _BYTE
  14.     Emc AS _BYTE
  15.     Weapon1 AS _BYTE
  16.     Weapon2 AS _BYTE
  17.     Weapon3 AS _BYTE
  18.     Weapon4 AS _BYTE
  19.     Count1 AS _BYTE
  20.     Count2 AS _BYTE
  21.     Count3 AS _BYTE
  22.     Count4 AS _BYTE
  23.     Special1 AS _BYTE
  24.     Special2 AS _BYTE
  25.     Special3 AS _BYTE
  26.  
  27. DIM SHARED Ship(5) AS Ship_Data
  28.  
  29. RESTORE Starting_Ships
  30. FOR i = 0 TO 4
  31.     READ Ship(i).Nam
  32.     READ Ship(i).Siz
  33.     READ Ship(i).Img
  34.     READ Ship(i).Tons
  35.     READ Ship(i).Hits
  36.     READ Ship(i).Defn
  37.     READ Ship(i).Cost
  38.     READ Ship(i).Armor
  39.     READ Ship(i).Engine
  40.     READ Ship(i).Manuver
  41.     READ Ship(i).Computer
  42.     READ Ship(i).Shield
  43.     READ Ship(i).Emc
  44.     READ Ship(i).Weapon1
  45.     READ Ship(i).Weapon2
  46.     READ Ship(i).Weapon3
  47.     READ Ship(i).Weapon4
  48.     READ Ship(i).Count1
  49.     READ Ship(i).Count2
  50.     READ Ship(i).Count3
  51.     READ Ship(i).Count4
  52.     READ Ship(i).Special1
  53.     READ Ship(i).Special2
  54.     READ Ship(i).Special3
  55.     PRINT i
  56. FOR i = 0 TO 4
  57.     PRINT Ship(i).Nam, Ship(i).Cost, Ship(i).Img, Ship(i).Special1
  58.  
  59. Starting_Ships:
  60. DATA "Scout",0,1,40,3,2,6,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0
  61. DATA "Fighter",0,2,40,3,2,6,1,1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0
  62. DATA "Destroyer",1,7,200,18,1,36,1,1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0
  63. DATA "Bomber",1,8,200,18,1,36,1,1,1,0,0,0,3,0,0,0,1,0,0,0,0,0,0
  64. DATA "Colony Ship",2,13,1000,100,0,200,1,1,1,0,0,0,0,0,0,0,0,0,0,0,2,0,0
  65.  
  66.  
« Last Edit: July 28, 2019, 09:59:52 am by bplus »

FellippeHeitor

  • Guest
Re: Just what does this error mean?
« Reply #3 on: July 28, 2019, 12:24:27 pm »
"Unexpected internal code reference to UDT" ?

I'm guessing it means I can not do what I wish too.
but I'm still curious as to why it won't allow it, as long as the data matches up.
to do in 1 line what will take many lines otherwise would seem logical.
I can do it the long way of course, I was just hoping for a simpler, faster, and shorter one liner way when the IDE displayed that error.

Just a different description to the same error, exactly as QB4.5 would complain:
  [ You are not allowed to view this attachment ]  

I understand the intention and it totally makes sense.

This fits into a "feature request" type of report.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Just what does this error mean?
« Reply #4 on: July 28, 2019, 02:35:31 pm »
This fits into a "feature request" type of report.

Where would I submit that or could you take care of it Fellippe?

I rather thought it would work cause you can do that type of operation with a file,

OPEN "testfile.dat" FOR BINARY AS #1
PUT #1, , ships(0, 0)
'GET #1, , ships(0, 0)
CLOSE

and thats perfectly fine. So it was rather a surprise when READ complained.

Yeah, here is your work done for you ;D

Thanks Bplus, but thats how I wound up doing it for now anyway. Not sure I could use non fixed length string cause this data needs to be saved to a file and last I knew we couldn't write or read UDT variable length strings yet.
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Just what does this error mean?
« Reply #5 on: July 28, 2019, 02:48:16 pm »
Quote
Thanks Bplus, but thats how I wound up doing it for now anyway. Not sure I could use non fixed length string cause this data needs to be saved to a file and last I knew we couldn't write or read UDT variable length strings yet.

Is the problem reading writing to files? because I have been using variable strings in UDT, even as substitute for small arrays of points. I know Petr brought up an issue and Fellippe mentioned memory leak but I have not seen the problem replicated into something less complex than Petr's one example.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Just what does this error mean?
« Reply #6 on: July 28, 2019, 03:43:31 pm »
Quote
I rather thought it would work cause you can do that type of operation with a file,

OPEN "testfile.dat" FOR BINARY AS #1
PUT #1, , ships(0, 0)
'GET #1, , ships(0, 0)
CLOSE

and thats perfectly fine. So it was rather a surprise when READ complained.

Yes, it works. Both PUT and GET read the data in the file in the order they are defined in the TYPE block. That is, 4 bytes for LONG, or SINGLE, 2 for INTEGER, 1 for _BYTE, 8 for DOUBLE, and so on.
The reason READ didn't work is because it didn't know which part of the TYPE you'd like to include. You just specify this by the expression after the dot.

Please note that when writing to a binary file, the STRING type MUST be of the specified length.

BPlus, I'll try to simplify it to identify the error, but it won't be easy at all, because the program in which the error turned out uses binary reading from many files, many STRING variables, and also dynamic rewriting of array positions at runtime, so it will be really long . I tried some simple tests. Everything was alright. As I would say in Czech - I am the deer from this bug.

FellippeHeitor

  • Guest
Re: Just what does this error mean?
« Reply #7 on: July 28, 2019, 03:57:47 pm »
Where would I submit that or could you take care of it Fellippe?

Not my ballpark in terms of coding abilities.

Best place to make it not be forgotten is to open a feature request issue at https://github.com/Galleondragon/qb64/issues

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Just what does this error mean?
« Reply #8 on: July 28, 2019, 05:19:55 pm »
You can always use my MemToHex and HexToMem routines to work with the files, as so:

Code: QB64: [Select]
  1. TYPE Ship_Data
  2.     Nam AS STRING * 12
  3.     Siz AS INTEGER
  4.     Img AS _UNSIGNED _BYTE
  5.     Tons AS INTEGER
  6.     Hits AS INTEGER
  7.     Defn AS INTEGER
  8.     Cost AS INTEGER
  9.     Armor AS _BYTE
  10.     Engine AS _BYTE
  11.     Manuver AS _BYTE
  12.     Computer AS _BYTE
  13.     Shield AS _BYTE
  14.     Emc AS _BYTE
  15.     Weapon1 AS _BYTE
  16.     Weapon2 AS _BYTE
  17.     Weapon3 AS _BYTE
  18.     Weapon4 AS _BYTE
  19.     Count1 AS _BYTE
  20.     Count2 AS _BYTE
  21.     Count3 AS _BYTE
  22.     Count4 AS _BYTE
  23.     Special1 AS _BYTE
  24.     Special2 AS _BYTE
  25.     Special3 AS _BYTE
  26.  
  27. DIM SHARED Ship(5) AS Ship_Data
  28. DIM m AS _MEM: m = _MEM(Ship())
  29.  
  30. RESTORE shipdata
  31. READ ShipData$
  32. HexToMem ShipData$, m
  33.  
  34. FOR i = 0 TO 4
  35.     PRINT Ship(i).Nam, Ship(i).Cost, Ship(i).Img, Ship(i).Special1
  36.  
  37.  
  38. shipdata:
  39. DATA "53636F757420202020202020000001280003000200060001010100000000000000000000000100004669676874657220202020200000022800030002000600010101000000010000000100000000000044657374726F796572202020010007C8001200010024000101010000000100000001000000000000426F6D626572202020202020010008C8001200010024000101010000000300000001000000000000436F6C6F6E7920536869702002000DE80364000000C800010101000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
  40.  
  41.  
  42.  
  43. FUNCTION MemToHex$ (m AS _MEM)
  44.     s = ConvertOffset(m.SIZE) - 1
  45.     FOR i = 0 TO s
  46.         _MEMGET m, m.OFFSET + i, b
  47.         h$ = HEX$(b)
  48.         IF LEN(h$) = 1 THEN h$ = "0" + h$
  49.         MemToHex$ = MemToHex$ + h$
  50.     NEXT
  51.  
  52. SUB HexToMem (hx$, m AS _MEM)
  53.     DIM i AS _INTEGER64
  54.     FOR i = 1 TO LEN(hx$) STEP 2
  55.         h = VAL("&H" + MID$(hx$, i, 2))
  56.         _MEMPUT m, m.OFFSET + i \ 2, h
  57.     NEXT
  58.  
  59. FUNCTION ConvertOffset&& (value AS _OFFSET)
  60.     DIM m AS _MEM 'Define a memblock
  61.     m = _MEM(value) 'Point it to use value
  62.     $IF 64BIT THEN
  63.         'On 64 bit OSes, an OFFSET is 8 bytes in size.  We can put it directly into an Integer64
  64.         _MEMGET m, m.OFFSET, ConvertOffset&& 'Get the contents of the memblock and put the values there directly into ConvertOffset&&
  65.     $ELSE
  66.         'However, on 32 bit OSes, an OFFSET is only 4 bytes.  We need to put it into a LONG variable first
  67.         _MEMGET m, m.OFFSET, temp& 'Like this
  68.         ConvertOffset&& = temp& 'And then assign that long value to ConvertOffset&&
  69.     $END IF
  70.     _MEMFREE m 'Free the memblock

I used bplus's code to put the data into the memblock initially, and then I copied the hex file to the clipboard and erased the program so we could get the data back in one go and place the whole memblock back into memory in one single go, as illustrated above.

I don't use these routines to save TYPE data so often, but I've found them endlessly useful for saving image data.  Just point the MemToHex routine to a memimage, and then save them to the clipboard and paste them as DATA statements for embedding into my main programs.


One caveat:

As you said, "we couldn't write or read UDT variable length strings yet.", and you're right.  We still can't GET/PUT any TYPE which has a variable length string in it -- and neither can we use _MEM with variable length strings.  If you notice in the demo above, I changed the type to STRING * 12.  _MEM requires fixed length strings, and so do these routines.

Use HexToMem and MemToHex to quickly save/load/embed full blocks of memory in one quick go.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Just what does this error mean?
« Reply #9 on: July 30, 2019, 07:40:18 am »
I rather thought it would work cause you can do that type of operation with a file,

OPEN "testfile.dat" FOR BINARY AS #1
PUT #1, , ships(0, 0)
'GET #1, , ships(0, 0)
CLOSE

and thats perfectly fine. So it was rather a surprise when READ complained.

I ran into a similar issue working with TYPE variables, while working with a user defined vector endpoint variable. I could equate one variable to another and the whole thing would transfer, but I couldn't do any other math like operations without isolating the individual elements. QB64 has to know what it's working on. It's reading one element at a time and has to know where it's going or what's being done to it. With file inputs and overall equates it presumes proper element order and rolls with it.

BTW, given the project I'm into now, I'm kind of interested in where you're going with this.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Just what does this error mean?
« Reply #10 on: July 31, 2019, 01:17:34 pm »
BTW, given the project I'm into now, I'm kind of interested in where you're going with this.

If you've every played, or heard of, Master Of Orion (1994) thats what I'm shooting for. Nearly done with the basic game  interfaces(menus). Now we'll see how far I can get in the logic aspect of the game, typically where I start to lose a project. Some of the logic I've figured out and some I can fake, but there are aspects that just baffle me. Getting the galactic distribution correct will be the first hurdle. I can get the individual systems to generate fairly correctly but getting them placed reasonably well I'm not sure on.
Granted after becoming radioactive I only have a half-life!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Just what does this error mean?
« Reply #11 on: July 31, 2019, 01:54:06 pm »
Hi Cobalt,

I found this game on YouTube - wow this will be a lot work! I am never played this game. It look as really great project. I wish you many success when developing this game.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Just what does this error mean?
« Reply #12 on: July 31, 2019, 05:27:35 pm »
If you've every played, or heard of, Master Of Orion (1994) thats what I'm shooting for. Nearly done with the basic game  interfaces(menus). Now we'll see how far I can get in the logic aspect of the game, typically where I start to lose a project. Some of the logic I've figured out and some I can fake, but there are aspects that just baffle me. Getting the galactic distribution correct will be the first hurdle. I can get the individual systems to generate fairly correctly but getting them placed reasonably well I'm not sure on.

It looks very much like a space based "Civilization" type of game. I'm an occasional Civ binger, so that sounds like a seriously cool project there