September 18, 2021, 18:48:08

Author Topic: can we bring back The Goto and #label commands into NG  (Read 2591 times)

Online Steve Elliott

  • Hero Member
  • *****
  • Posts: 3225
  • elgol
Re: can we bring back The Goto and #label commands into NG
« Reply #15 on: August 13, 2020, 12:39:39 »
Just replace labels with functions:

Code: [Select]

If KeyHit(KEY_1) Then drumplay()

...

function drumplay()

... code here

end function

Windows 10 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
MacOS Big Sur 64-bit, 8Gb RAM, Intel i5 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB
Linux Mint 19.3 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
Raspberry pi 3, pi 4, pi 400, BBC B, C64, ZX Spectrum

Offline wadmixfm

  • Full Member
  • ***
  • Posts: 137
Re: can we bring back The Goto and #label commands into NG
« Reply #16 on: August 13, 2020, 12:46:04 »
yeah i tried that

can you call another place from that function ???

can you add a function in a function ??


Online Steve Elliott

  • Hero Member
  • *****
  • Posts: 3225
  • elgol
Re: can we bring back The Goto and #label commands into NG
« Reply #17 on: August 13, 2020, 12:50:42 »
Quote
yeah i tried that

can you call another place from that function ???

can you add a function in a function ??

You tried that and what?  It didn't work??  It should.

Yes, you can call other functions from a function.

Why would you add a function to a function??  Just call several functions from a function if you want.
« Last Edit: August 13, 2020, 12:54:21 by Steve Elliott »
Windows 10 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
MacOS Big Sur 64-bit, 8Gb RAM, Intel i5 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB
Linux Mint 19.3 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
Raspberry pi 3, pi 4, pi 400, BBC B, C64, ZX Spectrum

Offline wadmixfm

  • Full Member
  • ***
  • Posts: 137
Re: can we bring back The Goto and #label commands into NG
« Reply #18 on: August 13, 2020, 12:57:19 »
tried the code you sent

when calling a function do you address it as

program()

or just

program

for example


Online Steve Elliott

  • Hero Member
  • *****
  • Posts: 3225
  • elgol
Re: can we bring back The Goto and #label commands into NG
« Reply #19 on: August 13, 2020, 13:06:25 »
You would use program() because you pass in data through variables within the brackets.  No data is required if you're just emulating a label therefore just use ().  But if you wanted to send say, x and y values to a function you could use program( x, y ).  Now BlitzMax needs to know what kind of data type it is, so when you define a function with integer (whole numbers) as an example you would say:

Code: [Select]
x = 10
y = 20

program( x, y )

...

Function program( x:Int, y:Int )

... process x and y here

End Function


Windows 10 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
MacOS Big Sur 64-bit, 8Gb RAM, Intel i5 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB
Linux Mint 19.3 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
Raspberry pi 3, pi 4, pi 400, BBC B, C64, ZX Spectrum

Offline wadmixfm

  • Full Member
  • ***
  • Posts: 137
Re: can we bring back The Goto and #label commands into NG
« Reply #20 on: August 13, 2020, 13:27:35 »
' how is this , it works but is this the right way to do it :)
'new specdrum 2
Import BaH.RtMidi
Import BRL.StandardIO
Import brl.D3D9Max2D
Import brl.Max2D
Import BRL.Retro
Import BRL.Random
Import BRL.Math
Import BRL.LinkedList
Import MaxGui.Drivers
Const GFX_WIDTH = 1024, GFX_HEIGHT = 768, BIT_DEPTH = 0, HERTZ = 75
AppTitle ="SpecDrum2 64bit Version "
'Center the screen on startup
SetGraphicsDriver GLMax2DDriver()
Graphics GFX_WIDTH, GFX_HEIGHT, BIT_DEPTH, HERTZ


Function begin()
Local hiya
hiya=0

Repeat
Cls

DrawText"Press 1 or 2 or 3 to quit",20,40
If KeyHit(KEY_1) Then test1
If KeyHit(KEY_2) Then test2
If KeyHit(KEY_3) Then End
Flip
Until hiya=1
End Function


Function test1()
Cls
DrawText "you have reached test 1",60,60
Flip
Delay 1500
begin()
End Function


Function test2()
Cls
DrawText "you have reached test 2",60,60
Flip
Delay 1500
begin()
End Function

begin()  ' this is the main call of the functions

Online Steve Elliott

  • Hero Member
  • *****
  • Posts: 3225
  • elgol
Re: can we bring back The Goto and #label commands into NG
« Reply #21 on: August 13, 2020, 14:19:07 »
Well it works is a good thing!   :D

I would re-write it a bit differently, but it works is the main thing.  Maybe somebody will jump in here as I don't have time right now.
Windows 10 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
MacOS Big Sur 64-bit, 8Gb RAM, Intel i5 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB
Linux Mint 19.3 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
Raspberry pi 3, pi 4, pi 400, BBC B, C64, ZX Spectrum

Offline wadmixfm

  • Full Member
  • ***
  • Posts: 137
Re: can we bring back The Goto and #label commands into NG
« Reply #22 on: August 13, 2020, 15:23:32 »
ahhhhhh i see

so once its called and ended it will have to be called again if i want to go back to that part of code

right ?


Offline TomToad

  • Hero Member
  • *****
  • Posts: 554
Re: can we bring back The Goto and #label commands into NG
« Reply #23 on: August 13, 2020, 17:11:11 »
There is a stack trace of sorts when using the debugger.  As you step through a program, line by line, the function call stack will be in the "debug" tab on the right.
------------------------------------------------
8 rabbits equals 1 rabbyte.

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal