Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why aren't these subroutines working on user defined types?
#1
I'm surely missing something somewhere but why aren't the subroutines working on the values in this user defined type?  
Shouldn't incr be increasing the values as it does for the variable A?

Code: (Select All)
Type score_type
    max As Integer
    cur As Integer
End Type

Type player_type
    power As score_type
    speed As score_type
    x As Integer
    y As Integer
End Type

Dim player As player_type

player.power.max = 100
player.power.cur = 0
player.x = 100
player.y = 100

A = 10
incr A, 1
Print A   

incr player.power.cur, 1
Print player.power.cur

incr player.x, 1
Print player.x

Sub incr (n, v)
    n = n + v
End Sub

Sub decr (n, v)
    n = n - v
End Sub
Reply
#2
I'm calling that a mystery. I can't see any obvious issues with the code. I've used lots of type in type constructions that worked fine. My vector math routines shouldn't work if there was a problem with type nesting.

EDIT:

I tried 'n AS INTEGER' in the SUB declaration and it worked.
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
Reply
#3
Type's don't match.   Those SUBs pass SINGLE, not INTEGER types.
Reply
#4
(11-10-2023, 02:04 AM)OldMoses Wrote: I'm calling that a mystery. I can't see any obvious issues with the code. I've used lots of type in type constructions that worked fine. My vector math routines shouldn't work if there was a problem with type nesting.

EDIT:

I tried 'n AS INTEGER' in the SUB declaration and it worked.

Doh, sloppy typing gets me again. Thaks for spotting it.
Reply
#5
This the obvious sample of code for what you are doing:

Code: (Select All)
Type score_type
  max As Integer
  cur As Integer
End Type

Type player_type
  power As score_type
  speed As score_type
  x As Integer
  y As Integer
End Type

Dim player As player_type

player.power.max = 100
player.power.cur = 0
player.x = 100
player.y = 100

A = 10
incr A, 1
Print A

incr player.power.cur, 1
Print player.power.cur

incr player.x, 1
Print player.x
End

Sub incr (n As Integer, v)
  n = n + v
End Sub

Sub decr (n As Integer, v)
  n = n - v
End Sub

Sub multiply (n As Integer, v)
  n = n * v
End Sub

Sub divide (n As Integer, v)
  n = n / v
End Sub

Sub power (n As Integer, v)
  n = n ^ v
End Sub
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Mac debugger not connecting, a user error! BlameTroi 0 99 02-07-2026, 06:18 PM
Last Post: BlameTroi
  plotting shapes not working madscijr 6 618 10-22-2025, 05:29 AM
Last Post: SMcNeill
  why isn't _FULLSCREEN working? madscijr 5 509 09-20-2025, 01:47 AM
Last Post: SMcNeill
  I'm working on an old MS-DOS thingy... KlamPs 2 502 08-25-2025, 09:43 AM
Last Post: hsiangch_ong
  blue circle isn't drawing and print isn't working? madscijr 12 2,301 09-21-2024, 06:13 PM
Last Post: madscijr

Forum Jump:


Users browsing this thread: 1 Guest(s)