can we bring back The Goto and #label commands into NG

Started by wadmixfm, August 12, 2020, 11:30:32

Previous topic - Next topic

Steve Elliott

Just replace labels with functions:



If KeyHit(KEY_1) Then drumplay()

...

function drumplay()

... code here

end function

Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

wadmixfm

yeah i tried that

can you call another place from that function ???

can you add a function in a function ??


Steve Elliott

#17
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.
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

wadmixfm

tried the code you sent

when calling a function do you address it as

program()

or just

program

for example


Steve Elliott

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:


x = 10
y = 20

program( x, y )

...

Function program( x:Int, y:Int )

... process x and y here

End Function



Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

wadmixfm

' 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

Steve Elliott

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.
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

wadmixfm

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 ?


TomToad

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.