Author |
Topic: help with programming (Read 972 times) |
|
norma
New Member
member is offline


Gender: 
Posts: 3
|
 |
help with programming
« Thread started on: Jul 19th, 2009, 2:32pm » |
|
Looking for help – I am new to BB4W though I was experienced with GFA Basic on the Atari ST, so please excuse beginner’s ignorance. I thought it would be fun to write a traditional 70s or 80s text based adventure, Colossal Cave style, but I am stuck on the very simple point of updating the elements in a string array as the needed descriptions change with player’s actions. Examples of what I mean: The array Room$(100)) contains a brief description of each room and player enters room 36. Room$(36) announces the presence of a big spider. Player kills spider, but then the program has to update room 36’s desciption so that next time player enters room 36 he is told”You are passing a dead spider”. The obvious replacement line of Room$(36)=” dead spider, etc” once the spider is flagged as dead is simply not accepted by BB4W. Likewise, player starts a rock fall in the north, his exits from the room were originally ‘north, south and up’, but it seems impossible to update the room exits after the blockage to only ‘south and up’ in the appropriate directions array for that room’s array element. I have considered replacing the arrays with hundreds of separate messages, but then I can’t run through the 42 or so objects the player can see or pick up with a FOR NEXT loop to see if any are present in the current room. No doubt a matter of finding the correct syntax but I think I have tried everything and I’m reluctant to scrap pages of programming on such a simple point. So how do I update the messages held in the arrays? Any advice? Norma.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: help with programming
« Reply #1 on: Jul 19th, 2009, 3:58pm » |
|
Quote:The obvious replacement line of Room$(36)=” dead spider, etc” once the spider is flagged as dead is simply not accepted |
|
What happens? Do you get an error message (if so, what is it)? I'm wondering whether you're trying to split a long string between two or more lines; the correct syntax for that is:
Code: Room$(36) = "First part of string " + \
\ "second part of string " + \
\ "final part of string" If this isn't it, please list a program snippet which demonstrates the problem you are having.
Richard.
|
|
Logged
|
|
|
|
norma
New Member
member is offline


Gender: 
Posts: 3
|
 |
Re: help with programming
« Reply #2 on: Jul 19th, 2009, 8:01pm » |
|
Hi, Thanks for quick reply. In all my pages of stuff, I can't right now find a good example, (typical!) but the invariable response to all my attempts was "Bad use of array". None of the strings are long enough to divide – after all this text only style of early adventures used to have to fit into 64K! Could it be because, with the sheer amount of data to enter, I have listed the array elements in PROCs for loading, such as (example only, not from program, following,) DEF PROC_FillVerb$ Verb$(1)="go" Verb$(2)="get" etc etc etc up to to Verb$(55) ENDPROC
and then expect to be able to write DIM Verb$(55) Verb$()=”” PROC FillVerb$ PRINT Verb$(2)
to see “get” when I run the program?
I do prefer to fill or change array elements directly instead of using READ and DATA because I invariably get the DATA in the wrong order, but even after filling with DATA, I still didn’t find I could then replace the original string in the filled array with a new one.
I expect I have just done something daft and should have persevered more, as I deduce from your reply that changing an array element during a program can be done. As a fairly new user I need plenty of practice still. It is years since I used to program the old Atari ST. Norma.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: help with programming
« Reply #3 on: Jul 19th, 2009, 9:51pm » |
|
Quote:the invariable response to all my attempts was "Bad use of array" |
|
There are several possible causes, but the most common is simply trying to access an element of an array before it has been DIMensioned!
Quote:Could it be because, with the sheer amount of data to enter, I have listed the array elements in PROCs for loading |
|
No, it makes no difference (especially as you appear to be using a global array). Rather than speculating, why not simply try it:
Code: DIM Verb$(55)
Verb$()="ABSABS"
PROC_FillVerb$
PRINT Verb$(2)
END
DEF PROC_FillVerb$
Verb$(1)="go"
Verb$(2)="get"
ENDPROC If you run that code (you can copy-and-paste it from here into BB4W) you will find it runs fine.
Quote:I deduce from your reply that changing an array element during a program can be done |
|
Of course. Perhaps you might find it helpful to work through the Beginners' Tutorial, especially the chapter on arrays:
http://www.bbcbasic.co.uk/bbcwin/tutorial/chapter14.html
Richard.
|
|
Logged
|
|
|
|
norma
New Member
member is offline


Gender: 
Posts: 3
|
 |
Re: help with programming
« Reply #4 on: Jul 21st, 2009, 08:38am » |
|
Again many thinks, especially as my problems have to have been from a silly mistake entered somewhere that I was blind to and didn’t search for long enough. Even so it is very reassuring to get confirmation that I am on the right lines. This has introduced me to the message board anyway, which is good.
On the suggestions you made, yes I had remembered to DIMension the arrays, but I am relieved to hear that it is okay to fill arrays from PROCs as this program has so much text. In fact apart from small movement routines and a bit of error checking it is pretty well all text entry so the PROCs simplify it a lot.
On the excellent Beginner’s Tutorial, too, I actually have it all printed out in a spiral bound notebook, and find it very helpful. On this occasion though, I turned to the pages on arrays and though there is plenty about them, I found no specific comment on changing an element in an existing array. Result panic – new programming language – is some special method used – rush for help!
Well, thank again for your time and I will persevere longer in future before running for help. As far as I know I was following the pattern you have given. Possibly my background in using mainly Forth rather than Basic gives me a tendency to enter things backwards – Forth postfix notation – and that could certainly blind me to an obvious mistake! Norma
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: help with programming
« Reply #5 on: Jul 21st, 2009, 11:16am » |
|
Quote:I found no specific comment on changing an element in an existing array |
|
True. It's always difficult for somebody writing a tutorial to anticipate the needs of their target audience (although I think Peter Nairn did a pretty good job!).
As a general rule anything you can do with an ordinary variable you can also do with an array element of the same type. So you can use an element of a string array (e.g. Room$(36)) just as you would use a simple string variable (e.g. Room36$); for example you can read it, write it, modify it, pass it as a parameter, make it LOCAL, PRINT it, find its memory address etc. etc.
It's the sort of 'unwritten rule' that an experienced programmer tends not even to think about, but which a beginner may need to have spelled out.
Richard.
|
« Last Edit: Jul 21st, 2009, 10:19pm by admin » |
Logged
|
|
|
|
dynamic35
New Member
member is offline


Gender: 
Posts: 34
|
 |
Re: help with programming
« Reply #6 on: Feb 17th, 2010, 9:28pm » |
|
I would like to know what is the way to kill extra instances of a program Sometimes I see 2-20 copies of the very same program existing and only one is enough. This takes place some times when you base the calling control in timers like when you use a TIME$ command that works in second level and then - based on equivalence of your tag time with TIME$'s time , followed by sys ShellExecute", @hwnd%, the program... this sys ..fetches many copies of the program into memory in one second slot Rgs N62E25 Ps this happens while being ofcource in a loop and you may get rid of the problem by the WAIT 100 command after the sys call for example REPEAT t$=MID$(TIME$,17,8) IF t$="14:30:01" THEN SYS "ShellExecute", @hwnd%, 0, "Run1.exe", "", "C:\Program Files\runs", 1
REM WAIT 100 here helps to limit instances of program Run1.exe in 2
UNTIL INKEY(10)=0
|
« Last Edit: Feb 17th, 2010, 9:46pm by dynamic35 » |
Logged
|
|
|
|
Richard Russell
Guest
|
 |
Re: help with programming
« Reply #7 on: Feb 17th, 2010, 10:19pm » |
|
on Feb 17th, 2010, 9:28pm, dynamic35 wrote:I would like to know what is the way to kill extra instances of a program |
|
Not exactly answering the question, but wouldn't it be easier to prevent the creation of multiple instances in the first place? Using a simple Boolean flag should easily achieve that (set the flag when TIME$ matches the specified time, reset it when it doesn't).
Again not answering the question, but if the program of which multiple instances are being created is one you have written yourself, you can prevent it using the code here:
http://bb4w.wikispaces.com/Detecting+a+second+instance+of+a+program
Although I can't help feeling that preventing multiple instances is the better way to proceed, terminating a program is often just a matter of posting it a WM_CLOSE message. Of course for that you must know its window handle, which could be a little tricky if there are several instances (SYS "FindWindow" only works safely if the window has a unique title).
Richard.
|
|
Logged
|
|
|
|
dynamic35
New Member
member is offline


Gender: 
Posts: 34
|
 |
Re: help with programming
« Reply #8 on: Feb 24th, 2010, 11:25pm » |
|
Could you please give example of killing a program among many programs coming in in sequency by TIME$ testing from day to day I have a main process POX12 that calls various modules -say wall watch graphics=POX1 at 11:00 and at 15:00 and a measurement run with own graphics on screen, POX2 (hiding watch), at 11:15 and at 15:23
I want to kill Pox2 when POX 1 is active and I want to kill Pox1 when Pox2 is active
So I do not find anywhere what is the call kill pox1 and pox2 here like... ------------------------------ IF TIME$=m1$ THEN SYS "ShellExecute", @hwnd%, 0, "pox1.exe", "", "C:\Program Files\poxes\" ****KILL here Pox2*** ENDIF
IF TIME$=m2$ THEN SYS "ShellExecute", @hwnd%, 0, "pox2.exe", "", "C:\Program Files\poxes" ****KILL here Pox1**** ENDIF
|
|
Logged
|
|
|
|
dynamic35
New Member
member is offline


Gender: 
Posts: 34
|
 |
Re: help with programming
« Reply #10 on: Feb 27th, 2010, 6:33pm » |
|
Thank you Malcomm & Richard
So this seems to close A$ being a string found in among tittle bar of instance to be closed online.
INSTALL @lib$+"CALLBACK" index% = 1 lParam% = 0 DIM hWnd%(1000) SYS FN_syscalls("EnumWindows"), FN_callback(FNenumfunc(),2), lParam% ret% = FN_sysresult WM_CLOSE = &10 nMaxCount% = 255 DIM lpString% nMaxCount%, lpszFileName% nMaxCount% PRINT "List of visible windows with Process ID and module name" PRINT "=======================================================" ' FOR i% = 1 TO index% $$lpszFileName% = "" $$lpString% = "" SYS "GetWindowText", hWnd%(i%), lpString%, nMaxCount% SYS "IsWindowVisible", hWnd%(i%) TO vis% SYS "GetWindowModuleFileName", hWnd%(i%), lpszFileName%, nMaxCount% SYS "GetWindowThreadProcessId", hWnd%(i%), ^pid% TO tpid% IF vis% AND $$lpString% <> "" THEN COLOUR 0: PRINT "* " $$lpString% COLOUR 1: PRINT " [pid=" + STR$(pid%) + "] ", $$lpszFileName% REM 1 -------------Dynamic35 insert-------------- A$="ToBeClosed.exe" IF INSTR($$lpString%,A$) THEN SYS "SendMessage", hWnd%(i%), WM_CLOSE, 0, 0 ENDIF REM 2 ENDIF NEXT END DEF FNenumfunc(hwnd%, lparam%) hWnd%(index%) = hwnd% index% += 1 = 1
|
|
Logged
|
|
|
|
Malcolm
Guest
|
 |
Re: help with programming
« Reply #11 on: Feb 27th, 2010, 7:54pm » |
|
You could probably achieve your aim with messaging.
I think you can broadcast a message with a custom message number. If the other program has a polling loop looking for messages you could operate that way. The two could have different messages so that you can control things.
|
|
Logged
|
|
|
|
|