• Print

Author Topic: Use qb64 to help realtime development of better game and interactive strategies  (Read 329 times)

Mrwhy

  • Hero Member
  • *****
  • Posts: 2890
  • My Dad called me Mr Why when I was 5.
    • Email
Use qb64 to help realtime development of better game and interactive strategies
« on: February 17, 2013, 04:00:06 AM »
Kind and helpful folk at QB64 have already showed me how to stop (pause) a program and save the latest values of all the variables.
In real-time interactive progs , such as GAMES, it would be great to be able to RESUME play This can be done in both qb45 and qb64 direct from the keyboard key  <PAUSE>
Then for diagnostics etc  knowing the current variable values is  extremely
useful.
Now qb64 must know and RETAIN these values – or it would not have been able to tell me!

In both qb45 and qb64 it is easy enough to restart (resume) the prog and in qb45 you can make small changes in the PROG before resuming! They may be small but hugely affect what happens NEXT.
Not at all the same as rerunning again from the beginning with the changes already made!

This is invaluable for online realtime development and discovery of interesting strategies – SEEING “what would happen NEXT" if that change was made at that point in the game or program progress.


Is there a way to permit us to make tiny changes in the prog DURING a pause and then resume play, like we can in QB45 – or must this await a real-time interpreter?
« Last Edit: February 17, 2013, 04:56:14 AM by Mrwhy »

OlDosLover

  • Hero Member
  • *****
  • Posts: 3859
  • OlDosLover
    • Email
Re: Use qb64 to help realtime development of better game and interactive strategies
« Reply #1 on: February 17, 2013, 04:04:12 AM »
Hi all,
    I think you are confusing the fact that QB45 has the interepreter that you are using to change variables. QB64 is a compiler.
OlDosLover.

Mrwhy

  • Hero Member
  • *****
  • Posts: 2890
  • My Dad called me Mr Why when I was 5.
    • Email
Re: Use qb64 to help realtime development of better game and interactive strategies
« Reply #2 on: February 17, 2013, 04:27:38 AM »
Well Oldos, kind folk here found me a way to get the latest values of the variables - a GREAT help in fixing progs that fail (my strongpoint, that ::) )
So I am hoping they can invent a way to overcome the fact that QB64 (lacking as yet an interpreter version) does not make the prog AVAILABLE for us to modify.
Yet it is "there" (in C++ gobledy-goo) thus it CAN resume - but only to do the same as it was going to do before (No help at all is discovering strategies to improve games and progs).
« Last Edit: February 17, 2013, 04:57:45 AM by Mrwhy »

Mrwhy

  • Hero Member
  • *****
  • Posts: 2890
  • My Dad called me Mr Why when I was 5.
    • Email
Re: Use qb64 to help realtime development of better game and interactive strategies
« Reply #3 on: February 17, 2013, 04:59:25 AM »
Yes, you are right and thank you.
I have now made the changes from "compiler" to "interpreter" in my above posts.

OlDosLover

  • Hero Member
  • *****
  • Posts: 3859
  • OlDosLover
    • Email
Re: Use qb64 to help realtime development of better game and interactive strategies
« Reply #4 on: February 17, 2013, 05:25:46 AM »
Hi all,
   
Quote
Is there a way to permit us to make tiny changes in the prog DURING a pause and then resume play, like we can in QB45 – or must this await a real-time interpreter?
    Yes of course there is. Firstly the interpreter allows you to change variables in the immediate window . In the compiler there is no immediate window. You will have to make your own "immediate" window. I'd imagine you'd need a routine to trigger  off a particular keyboard key to go to another place in the program that is like an endless loop that can only exit with another particular keypress. During this "immediate window" place youd have access to all shared variables and able to use keyboard input to change individual variables. I'd suggest you start out with a very simple program of a few variables and work on your entry and exit to that endles loop place. Then id work on keypresses to access individual variables with INPUT$. Good luck.
OlDosLover.

Mrwhy

  • Hero Member
  • *****
  • Posts: 2890
  • My Dad called me Mr Why when I was 5.
    • Email
Re: Use qb64 to help realtime development of better game and interactive strategies
« Reply #5 on: February 17, 2013, 10:32:29 AM »
Thanks Oldos- glad to hear it is possible

To see if I have a clue HOW, please let us think together about this example

Let's place on-screen a circle whose size and location varies continually in a pre-programmed manner. This is easy to pause, using the key  <PAUSE>
When we now hit another key the prog will CONTINUE where it left off - with every variable and command the same as before. It will IGNORE any new colour I request and simply give the same result it was going to give before we paused it

Now maybe this circle is the target in a shooting game and its colour signifies how easily it dodges  and resists damage when hit.
C++ knows what the colour WAS. But how do we CHANGE the colour and CONTINUE WITH THAT COULOR NOW CHANGED?

I agree this must be possible - for QB64 IS ABLE to tell me what the colour was (despite it being held in C++)
So it CAN put my  request "Now make the colour 14 from now on " (fron this point on in the prog) into C++ so it CAN obey it.

But me seeing it is possible is not at all like me seeing HOW to do it!

Your advice please.
I don't want to write subroutines into the prog to be called upon when requested.
I don't want to begin the prog over from the beginning
I want the freedom to change things "on the fly" so as to make discoveries about how to make the prog more interesting and dynamically controllable.


Can it accept my keybpoard input of the instruction "Circle (x,y),14" , convert it into C++ and then resume the prog (with the colour 14) from the point where I paused it?
This would represent, for example, a target that suddenly put up a different defensive barrier.


Your advice please!
Yes C++ (in its own language) knows what the colour WAS
How do we get it to continue, but now with the new colour?

SMcNeill

  • Hero Member
  • *****
  • Posts: 2414
    • Email
Re: Use qb64 to help realtime development of better game and interactive strategies
« Reply #6 on: February 17, 2013, 11:47:18 AM »
So here's one of the simplest examples of how to do something like this for you.    All this does is put a circle on the screen.  No movement routine or anything of that sort.   We just want to draw a circle on a SCREEN 12 screen, and then be able to pause the program, go in, and alter that circle on the fly.

Code: [Select]
x = 100
y = 100
rad = 50
clr = 10


SCREEN 12
DO
    _LIMIT 10
    CLS
    CIRCLE (x, y), rad, clr
    PAINT (x, y), clr
    _DISPLAY
    a$ = INKEY$

    IF a$ <> "" THEN
        SELECT CASE UCASE$(a$)
            CASE "P"
                _AUTODISPLAY
                LOCATE 1, 1: PRINT "PAUSED"
                DO
                    b$ = INKEY$
                    IF b$ <> "" THEN
                        SELECT CASE UCASE$(b$)
                            CASE "X": INPUT "X = "; x
                            CASE "Y": INPUT "Y = "; y
                            CASE "C": INPUT "Color = "; clr
                            CASE "R": INPUT "Radius = "; rad
                            CASE "P": EXIT DO
                            CASE CHR$(27): SYSTEM
                        END SELECT
                    END IF
                LOOP
            CASE CHR$(27): SYSTEM
        END SELECT
    END IF
LOOP UNTIL INKEY$ <> ""

We use P to start and stop the PAUSE routine.   When it's not paused, we look at the pretty circle as we set it.  X/Y, radius, color -- all we can change on at a whim.
P to pause it.
X to change the value of its x-coordinate.
Y to change y-coord
C to change color
R to change radius
P to unpause it, and watch the new changes....

A simple interrupt and update command.  :)
http://bit.ly/TextImage -- Library of QB64 code to manipulate text and images, as a BM library.
http://bit.ly/Color32 -- A set of color CONST for use in 32 bit mode, as a BI library.

http://bit.ly/DataToDrive - A set of routines to quickly and easily get data to and from the disk.  BI and BM files

Mrwhy

  • Hero Member
  • *****
  • Posts: 2890
  • My Dad called me Mr Why when I was 5.
    • Email
Re: Use qb64 to help realtime development of better game and interactive strategies
« Reply #7 on: February 17, 2013, 12:17:18 PM »
Yes that is very helpful.

Only one snag.
In a typical prog there are scores of variables and loops each of which can be changed in dozens of ways - both quantity and quality (nature).

So I would need to ADD to my prog thousands of "go to"s one for each change I wanted.
Trouble with that is it is limited to changes that ALREADY I knew I'd want to change, before any program real-time experiments had helped me discover and get excited about new ideas and strategies.

So ideally I want to type in something that qb64 AND I understand.
It then converts this wish of mine into C++ activity and resumes with that activity now in place.
From that point on it's activity is MODIFIED by the changes I asked for and it will SHOW me "what would happen if"

Does qb64 being compiled make this specially difficult to do?
It IS capable of telling ME what the latest up-to-date variables are, so logically it should be able to do the reverse - tell itself in C++ code what I want changed, for when it resumes.

Many thanks

OlDosLover

  • Hero Member
  • *****
  • Posts: 3859
  • OlDosLover
    • Email
Re: Use qb64 to help realtime development of better game and interactive strategies
« Reply #8 on: February 17, 2013, 03:43:28 PM »
Hi all,
    The way id do this is:
Quote
You will have to make your own "immediate" window. I'd imagine you'd need a routine to trigger  off a particular keyboard key to go to another place in the program that is like an endless loop that can only exit with another particular keypress.

Code: [Select]
REM
DEFLNG A-Z

CONST True = -1, False = 0

DIM SHARED Value(1 TO 10) AS LONG

ForeGround& = _NEWIMAGE(640, 480, 32)
BackGround& = _NEWIMAGE(640, 480, 32)

SCREEN ForeGround&
Stuck = False
GOSUB DefineKeys1

DO
  _LIMIT 30
  IF Stuck THEN
    PRINT "Timer = "; TIMER;
  ELSE
    PRINT "Dice = "; INT(RND * 100) + 1;
  END IF
  _DISPLAY
LOOP UNTIL _KEYDOWN(27)
SLEEP
SYSTEM

DefineKeys1:
'                                          Set up the EntryKey
KEY(30) ON '                               <--- F11 is ON
ON KEY(30) GOSUB EntryKey '                <-- tell it where to go
RETURN

EntryKey:
KEY(30) OFF '                              <-- turn entry key OFF as we dont want it to call itself
SCREEN BackGround& '                       <-- change screens
Stuck = True '                             <-- toggle our control variable
'                                          Set up the ExitKey
KEY(31) ON '                               <--- F12 is ON
ON KEY(31) GOSUB ExitKey '                 <-- tell it where to go
PRINT "we are in BACKGROUND "; Stuck
SOUND 800, 3
RETURN

ExitKey:
KEY(31) OFF '                             <-- turn exit key OFF as we dont want it to call itself
SCREEN ForeGround& '                      <-- change screens
Stuck = False '                           <-- toggle our control variable
PRINT "we are in FOREGROUND "; Stuck
SOUND 1200, 3
KEY(30) ON '                              <-- turn entry key back ON
RETURN

PS F11 gets us into our "immediate window" and F12 returns us to our graphics window.
OlDosLover.
« Last Edit: February 17, 2013, 09:48:00 PM by OlDosLover »

OlDosLover

  • Hero Member
  • *****
  • Posts: 3859
  • OlDosLover
    • Email
Re: Use qb64 to help realtime development of better game and interactive strategies
« Reply #9 on: February 17, 2013, 03:55:31 PM »
Hi all,
    Nice simple and crisp idea Steve. I like it.
    MrWhy you are biting off more than you can chew again. There is a viable way to do this but start simply and work your way up to more complicated.
Quote
Only one snag.
In a typical prog there are scores of variables and loops each of which can be changed in dozens of ways - both quantity and quality (nature).
    Limit your wanted to change variables to something managable like 10 max.

Quote
So I would need to ADD to my prog thousands of "go to"s one for each change I wanted.
    Stop using GOTO's and swap to GOSUBS as the flow of the program is easier to decifer.

Quote
Trouble with that is it is limited to changes that ALREADY I knew I'd want to change, before any program real-time experiments had helped me discover and get excited about new ideas and strategies.
    Here we are all limited to the variables we choose to use in our programs and the range of those variables are decided with the types we use. QB64 isn't smart enough to read your mind and write code accordingly. You will have to write the code limited to what you can express , the same as all of us.
Don't read my comments negatively. This is achievable but you need to be VERY defined and not abstract.
OlDosLover.

OlDosLover

  • Hero Member
  • *****
  • Posts: 3859
  • OlDosLover
    • Email
Re: Use qb64 to help realtime development of better game and interactive strategies
« Reply #10 on: February 17, 2013, 09:43:12 PM »
Hi all,
    Here is how i would change the individual variables under user control. This is an example and ESCAPE key exits. This is designed to be married to my above program that changes screens.
Code: [Select]
REM
DEFLNG A-Z

CONST True = -1, False = 0

DIM SHARED Value(1 TO 10) AS INTEGER

ForeGround& = _NEWIMAGE(640, 480, 32)

SCREEN ForeGround&
GOSUB Defaults
GOSUB DefineKeys2

DO
  _LIMIT 30
  CLS
  LOCATE 6, 1
  FOR t = 1 TO 10
    PRINT "Value("; STR$(t); ") = "; Value(t)
  NEXT t
  LOCATE 25, 10: PRINT "WE can only change the first 10 values in our dim with F1 to F10"
  _DISPLAY
LOOP UNTIL _KEYDOWN(27)
SLEEP
SYSTEM

Defaults:
FOR t = 1 TO 10
  Value(t) = 100
NEXT t
RETURN

DefineKeys2: '                             Set up the Modify Entry Key
FOR t = 1 TO 10
  KEY(t) ON '                              <--- F1 to F10 is ON
  SELECT CASE t '                          <-- tell it where to go
    CASE 1
      ON KEY(1) GOSUB Entry1
    CASE 2
      ON KEY(2) GOSUB Entry2
    CASE 3
      ON KEY(3) GOSUB Entry3
    CASE 4
      ON KEY(4) GOSUB Entry4
    CASE 5
      ON KEY(5) GOSUB Entry5
    CASE 6
      ON KEY(6) GOSUB Entry6
    CASE 7
      ON KEY(7) GOSUB Entry7
    CASE 8
      ON KEY(8) GOSUB Entry8
    CASE 9
      ON KEY(9) GOSUB Entry9
    CASE 10
      ON KEY(10) GOSUB Entry10
      'tell it that we finished and exit this section
  END SELECT
NEXT t

RETURN

Entry1:
CaseCommon 1
RETURN

Entry2:
CaseCommon 2
RETURN

Entry3:
CaseCommon 3
RETURN

Entry4:
CaseCommon 4
RETURN

Entry5:
CaseCommon 5
RETURN

Entry6:
CaseCommon 6
RETURN

Entry7:
CaseCommon 7
RETURN

Entry8:
CaseCommon 8
RETURN

Entry9:
CaseCommon 9
RETURN

Entry10:
CaseCommon 10
RETURN

SUB CaseCommon (WhatKey AS INTEGER)
LOCATE 1, 1: PRINT STRING$(30, 32)
Label$ = "Enter new value for Value(" + LTRIM$(STR$(WhatKey)) + ")"
LOCATE 1, 1: PRINT Label$;
INPUT Entry$
NewEntry% = VAL(Entry$)
IF NewEntry% <> 0 THEN Value(WhatKey) = NewEntry%
END SUB

    This could be expanded but is limited by the number of unique Key(n) [32 i think].
OlDosLover.

Mrwhy

  • Hero Member
  • *****
  • Posts: 2890
  • My Dad called me Mr Why when I was 5.
    • Email
Re: Use qb64 to help realtime development of better game and interactive strategies
« Reply #11 on: February 17, 2013, 10:17:05 PM »
All these comments from everyone are very helpful and I an very impressed.
Maybe Oldos is right (certainly not at all negative!) that FIRST I must find simple things QB64 CAN do before I explore the limits of what we might be able to get it to do!

One of my problems is I want to know NOW  what effect a minor change may have - not have to rewrite an entire program to find out! QB45 does allow me to alter complete loops or program lines and then "continue from there on with those changes made" to see what happens.
Now they SAY "Any turing machine CAN DO what any other one can".
Are we discovering the true meaning of this oft-quoted "fact" when we compare what qb45 can do with what qb64 can do? (i.e. having to do extensive program re-writes and additions and recomplie in order to do what is so simply done under qb45)

New ideas come from being able to rapidly  see "what would happen if...."; not from exceeding your attention span by writing new code BEFORE you have discovered what you'd really like to do! ::) ;D ::) ??? ::)

OlDosLover

  • Hero Member
  • *****
  • Posts: 3859
  • OlDosLover
    • Email
Re: Use qb64 to help realtime development of better game and interactive strategies
« Reply #12 on: February 17, 2013, 10:25:17 PM »
Hi all,
   
Quote
not have to rewrite an entire program to find out! QB45 does allow me to alter complete loops or program lines and then "continue from there on with those changes made" to see what happens.
    So would every programmers on this site. We would all have to rewrite them to achieve what you want. It would be better to write it flexable to begin with. Also what you have traditionally done with the QB45 interpreter is NOT possible with QB64 as yet. My advice is stop using the interpreter and only use QB64 to achieve what you can currently do and start to learn the rest.
OlDosLover.

OlDosLover

  • Hero Member
  • *****
  • Posts: 3859
  • OlDosLover
    • Email
Re: Use qb64 to help realtime development of better game and interactive strategies
« Reply #13 on: February 18, 2013, 03:14:00 AM »
Hi all,
    Here are my two above programs married together. On running the program , F11 will get you into the "immediate window" and turn on F1 to F10 to allow you to edit any or all of the 10 variables in the Dim Value. F12 will exit out of "immediate window" and turn off  F1 to F10 and turn back on F11 to allow reentry into "immediate window" next pass.

Code: [Select]
REM
DEFLNG A-Z

CONST True = -1, False = 0

DIM SHARED Value(1 TO 10) AS LONG

ForeGround& = _NEWIMAGE(640, 480, 32)
BackGround& = _NEWIMAGE(640, 480, 32)

SCREEN ForeGround&
Stuck = False
GOSUB Defaults
GOSUB DefineKeys1

DO
  _LIMIT 30

  IF Stuck THEN
    CLS
    LOCATE 6, 1
    FOR t = 1 TO 10
      PRINT "Value("; STR$(t); ") = "; Value(t)
    NEXT t
    LOCATE 25, 10: PRINT "WE can only change the first 10 values in our dim with F1 to F10"
    _DISPLAY
  ELSE
    GOSUB MakBackground
    GOSUB MakObjects
  END IF

  _DISPLAY
LOOP UNTIL _KEYDOWN(27)
SLEEP
SYSTEM

Defaults:
Value(1) = 6 '     <-- the step value
Value(2) = 155 '   <-- the Red value of RGB32
Value(3) = a '     <-- the Green value of RGB32
Value(4) = 155 '   <-- the Blue value of RGB32
Value(5) = 0 '     <--
Value(6) = 1 '     <-- decide on object 1=circle , 2=square ,3=triangle
Value(7) = 320 '   <-- x of object
Value(8) = 240 '   <-- y of object
Value(9) = 100 '   <-- size of object
Value(10) = 0 '    <-- color of object
RETURN

MakBackground:
FOR y = 0 TO 479 STEP Value(1)
  Value(2) = y \ 2
  LINE (0, y)-(639, y + Value(1)), _RGB32(Value(2), Value(3), Value(4)), BF
NEXT y
RETURN

MakObjects:
SELECT CASE Value(6)
  CASE 1
    CIRCLE (Value(7), Value(8)), Value(9), _RGB32(Value(2), Value(3), Value(4))
  CASE 2
    LINE (Value(7) - Value(9) \ 2, Value(8) - Value(9) \ 2)-(Value(7) + Value(9) \ 2, Value(8) + Value(9) \ 2), _RGB32(Value(2), Value(3), Value(4)), BF
  CASE 3

  CASE ELSE
END SELECT
RETURN

DefineKeys1:
'                                          Set up the EntryKey
KEY(30) ON '                               <--- F11 is ON
ON KEY(30) GOSUB EntryKey '                <-- tell it where to go
RETURN

EntryKey:
KEY(30) OFF '                              <-- turn entry key OFF as we dont want it to call itself
SCREEN BackGround& '                       <-- change screens
Stuck = True '                             <-- toggle our control variable
'                                          Set up the ExitKey
KEY(31) ON '                               <--- F12 is ON
ON KEY(31) GOSUB ExitKey '                 <-- tell it where to go
PRINT "we are in BACKGROUND "; Stuck
SOUND 800, 3
GOSUB DefineKeys2 '                        <-- turn on F1 to F10 keys
RETURN

ExitKey:
KEY(31) OFF '                             <-- turn exit key OFF as we dont want it to call itself
SCREEN ForeGround& '                      <-- change screens
Stuck = False '                           <-- toggle our control variable
PRINT "we are in FOREGROUND "; Stuck
SOUND 1200, 3
KEY(30) ON '                              <-- turn entry key back ON
GOSUB DefineKeys3 '                       <-- turn off F1 to F10
RETURN

DefineKeys2: '                             Set up the Modify Entry Key
FOR t = 1 TO 10
  KEY(t) ON '                              <--- F1 to F10 is ON
  SELECT CASE t '                          <-- tell it where to go
    CASE 1
      ON KEY(1) GOSUB Entry1
    CASE 2
      ON KEY(2) GOSUB Entry2
    CASE 3
      ON KEY(3) GOSUB Entry3
    CASE 4
      ON KEY(4) GOSUB Entry4
    CASE 5
      ON KEY(5) GOSUB Entry5
    CASE 6
      ON KEY(6) GOSUB Entry6
    CASE 7
      ON KEY(7) GOSUB Entry7
    CASE 8
      ON KEY(8) GOSUB Entry8
    CASE 9
      ON KEY(9) GOSUB Entry9
    CASE 10
      ON KEY(10) GOSUB Entry10
      'tell it that we finished and exit this section
  END SELECT
NEXT t

RETURN

Entry1:
CaseCommon 1
RETURN

Entry2:
CaseCommon 2
RETURN

Entry3:
CaseCommon 3
RETURN

Entry4:
CaseCommon 4
RETURN

Entry5:
CaseCommon 5
RETURN

Entry6:
CaseCommon 6
RETURN

Entry7:
CaseCommon 7
RETURN

Entry8:
CaseCommon 8
RETURN

Entry9:
CaseCommon 9
RETURN

Entry10:
CaseCommon 10
RETURN

DefineKeys3: '                             Turn OFF F1 to F10
FOR t = 1 TO 10
  KEY(t) OFF
NEXT t
RETURN

SUB CaseCommon (WhatKey AS INTEGER)
LOCATE 1, 1: PRINT STRING$(30, 32)
Label$ = "Enter new value for Value(" + LTRIM$(STR$(WhatKey)) + ")"
LOCATE 1, 1: PRINT Label$;
INPUT Entry$
NewEntry% = VAL(Entry$)
IF NewEntry% <> 0 THEN Value(WhatKey) = NewEntry%
END SUB
P.S. This is expandable.

OlDosLover.
« Last Edit: February 18, 2013, 03:19:16 AM by OlDosLover »

Billbo

  • Sr. Member
  • ****
  • Posts: 286
    • Email
Re: Use qb64 to help realtime development of better game and interactive strategies
« Reply #14 on: February 18, 2013, 07:02:07 AM »
OlDosLover,

I just downloaded your program (the one that combines the other two). It would not compile in QB64 GL 0.974 (Galleon's repos version).
But, it did compile and run in QB64 GL 0.971.

Just indicated that compilation failed. No reason. Any ideas.

Bill

  • Print