Quote: "Right I figured out where it getting Tybalt from, the name section!"
Yes, go on...
Quote: "Now I got an Idea that it is something to do with 'dim' but I'm not sure, but I will keep trying"
Nope! Nothing to do with dim, the issue is with an image, not an array.
The issue is a really annoying one. DATA statements are treated as if they are in a big block, ignoring all the other instructions in-between. When you read data, the program reads from the next DATA statement in the list, it doesn't matter what comes between.
Now, I made two subroutines, "_init_recruits" and "_load_images", in that order, and they both contain DATA. However, I called them the other way around: "_load_images" first, then "_init_recruits", so when the program went to read in data for the image paths it started reading the recruit names instead because that was the first data in the file.
This can be solved by restoring (moving) the data cursor to a specified label, which is what I did to fix the error:
remstart
***** Main Source File *****
Project: Night Watch
Created: Monday, July 15, 2013
Edited by OBese87/Libervurto (commenting as 'OB')
--------------------------------
** VARIABLE CHANGES **
'RecruitSubMenu' → 'selectedRecruit'
'trustwothy' → 'loyal'
'loyalty' → 'lawful'
'NightWatchMainMenuSelection' → 'NWMenuCursor'
'NightWatchMoney' → 'NWMoney'
'NightWatchWeeklyCost' → 'NWWeeklyCost'
'RecruitmentSetup' → REMOVED: does nothing.
'RecruitmentMenu' → 'NWMenuView': now stores a value from 0-6 for the currently viewed menu:
0 = main menu, 1 = patrols, 2 = cases, 3 = finance, 4 = officers, 5 = recruits
(I am also using [6 = recruit profile] since it seems like a better solution than having to check if a recruit is selected,
but it's not an elegant solution and may change.)
--------------------------------
** PROGRAMMING COMMENTS **
* Why do you use absurdly long variable names, like 'NightWatchMainMenuSelection'? They are not helpful.
* Controlling some parts of the menus with keyboard and others with mouse is confusing.
* Think about how the program will be expanded while you are writing it. Examples of not doing this:
→ You did not use a variable for the portrait image number, even though you want to give the recruits different portraits in future.
→ You are clearly planning to add further menus, but you have rigidly coded in the recruitment menu as if it will be the only sub-menu.
--------------------------------
** GAME DESIGN THOUGHTS **
* There should be separate ledgers (books) for Patrols, Cases, Finances, Officers and Recruits.
* All books should be navigable by page-turning, with buttons acting like hyperlinks to certain pages.
* The recruit menu should be more like a list of names linking to the individual profiles.
* LOYALTY and LAWFULNESS
→ How do LOYALTY and LAWFULNESS effect the watchman's behaviour? Is their loyalty to their captain or to you? Could they be loyal to someone
above you, or are you the highest authority? I still think these terms are confusing and need rewording.
→ How are these statistics being gathered? Is it available from the start or do you have to interview/know the men to learn about their nature?
→ I think it would be better not to display numbers at all, the recruit's bio/bias text can be refined to give a good idea of their stats.
--------------------------------
** EXPLANATION OF THE SILKEY FUNCTION **
SILKEY, by Silverman/Libervurto, is a function for simplifying the use of Autonomous Assignment Variables (AAVs).
AAVs are self-governing variables, they instruct their own assignment via additional data stored within themselves.
You do not need to understand the inner workings of AAVs in order to use this function, you only need to interpret the return values.
SILKEY was designed for managing inputs, so I will explain the return values in that context, but it could be used to monitor
the changing state of any boolean variable.
RETURN VALUES:
Value State
0 idle
1 newly pressed
2 newly released
3 held
These values may seem to be in a strange order, but the order becomes logical once you consider their binary representations and the fact
that SILKEY operates a FILO system, which records both the previous and current state of the trigger within the return value itself.
----------------------------------------------------------------
remend
set image colorkey 255,174,201
NWMoney = 500
NWWeeklyCost = 0
gosub _load_images
gosub _init_recruits
rem **************** MAIN ****************
do
rem == MAIN MENU ==
if NWMenuView = 0
rem store inputs (OB: maybe store these keystate numbers in variables so they can be rebounded?)
`// menuControl = (<w> OR <up>) - (<s> OR <down>)
oldMenuControl = menuControl
menuControl = (keystate(208) || keystate(31)) - (keystate(200) || keystate(17))
selectKey = silkey(keystate(28),selectKey)
leftClick = silkey(mouseclick()=1,leftClick)
rem move cursor if change within bounds
if menuControl <> oldMenuControl
if NWMenuCursor+menucontrol <=4 and NWMenuCursor+menucontrol >=0 then inc NWMenuCursor,menuControl
endif
rem submenu select
if selectKey then NWMenuView = 5
// for now, all options lead to the recruit menu, but this will be replaced by: NWMenuView = NWMenuCursor+1
rem return to main menu
if leftClick and mouseInRegion(70,90,91,112) then NWMenuView = 0
rem display highlighted menu (patrols, cases, finance, officers, recruits)
paste image NWMenuCursor+1,0,0
else
rem submenus use a different base image
paste image 6,0,0
endif
Rem == RECRUITMENT MENU ==
If NWMenuView = 5
ink 0,0 `// OB: rgb(a,b,c) = a*65536 + b*256 + c ; so rgb(0,0,0) = 0
` debugging info
set cursor 0,0 : Print "Mouse X,Y:", mx, ",", my
set cursor 0,15 : Print "RecruitPage = ", RecruitPage
rem -- page control --
If RecruitPage > 0
text 84,370,"Previous Page"
If mouseInRegion(75,370,195,387) and leftClick = 1 then dec RecruitPage
rem update left page recruit to match page
leftPageRecruit = RecruitPage*2 +1
endif
If RecruitPage < 2
text 484,370,"Next Page"
If mouseInRegion(467,370,563,387) and leftClick = 1 then inc RecruitPage
rem update left page recruit to match page
leftPageRecruit = RecruitPage*2 +1
endif
` Return to main menu Button
paste image 21,70,90
rem -- display page contents -- (left page = 0, right page = 1)
for n = 0 to 1
current = leftPageRecruit + n
rem portraits
paste image recruit(leftPageRecruit).portrait,80,115
paste image recruit(rightPageRecruit).portrait,338,115
rem attribute bars
paste image 6 + recruit(current).loyal,85,180
paste image 6 + recruit(current).lawful,85,270
if recruit(current).recruited then recruitedStatus$ = "Recruited" else recruitedStatus$ = "Recruit"
text 182+n*258,105, recruit(current).firstname + " " + recruit(r).surname
center text 182+n*258,219,"Loyalty : " + str$(recruit(current).loyal)
center text 182+n*258,300,"Lawfulness : " + str$(recruit(current).lawful)
center text 182+n*258,335,recruitedStatus$
rem select recruit?
If recruit(current).recruited = 0 and leftClick = 1
if mouseInRegion(147+n*257,334,217+n*253,349) then NWMenuView = 6 : selectedRecruit = current
endif
next n
endif
rem == RECRUIT PROFILE PAGE ==
if NWMenuView = 6
Rem Recruit Person
center text 182,105,"Recruit Information"
text 70,130, "Loyalty : " + str$(recruit(selectedRecruit).loyal)
text 70,150, "Lawfulness : " + str$(recruit(selectedRecruit).lawful)
box 70,175,280,178
text 70,190, "Finance"
text 200,190,str$(NWMoney)
text 200,210,"-50"
box 150,230,280,233
text 200,240,str$(NWMoney-50)
text 70,255, "Weekly Cost"
text 200,255,"-" + str$(NWWeeklyCost)
text 70,270, "New Weekly Cost"
text 200,270,"-" + str$(NWWeeklyCost+25)
box 150,290,280,293
text 200,300,str$((NWMoney-50)-NWWeeklyCost-25)
center text 182,335,"Confirm Return"
paste image recruit(selectedRecruit).portrait,400,130
set text size 30
center text 440,220,recruit(selectedRecruit).firstname + " " + recruit(selectedRecruit).surname
set text size 12
rem determine recruit's bias (0=NEUTRAL;1=LAWFUL;2=LOYAL)
bias = recruit(selectedRecruit).lawful - recruit(selectedRecruit).loyal
bias = (bias<-2) + (abs(bias)>2)
rem display recruit bias text
text 340,270, recruit(selectedRecruit).firstname + " " + recruit(selectedRecruit).surname + recruitbias$(bias,0)
for i = 1 to 5 : text 340,270+i*20, recruitbias$(bias,i) : next i
rem confirm recruitment of selected recruit
if mouseInRegion(102,334,160,351) and leftClick
open to write 10,"Night Watch/Watchmen/RWM.txt"
write string 10,recruit(selectedRecruit).FirstName + " " + recruit(selectedRecruit).Surname
write string 10,str$(recruit(selectedRecruit).loyal)
write string 10,str$(recruit(selectedRecruit).Lawful)
recruit(selectedRecruit).recruited = 1
selectedRecruit = 0 : NWMenuView = 5
endif
Rem return to recruit menu
if mouseInRegion(212,334,266,348) and leftClick = 1 then selectedRecruit = 0 : NWMenuView = 5
endif
loop
end
rem ******** SUBROUTINES ********
_init_recruits:
restore _init_recruits `// this moves the data cursor to here so we don't read the wrong data
type recruitType
loyal as integer
lawful as integer
firstname as string
surname as string
recruited as boolean
portrait as integer
endtype
dim recruit(6) as recruitType
rem --- LOAD NAMES --
rem (OB: Might be a better idea to store names in a separate text file and read them in.)
rem first names
maxfirstname = 55
data "Merek","Carac","Ulric","Tybalt","Borin","Sadon","Terrowin","Rowan","Forthwind","Althalos","Fendrel","Brom","Hadrian","Walter","Oliver"
data "Clifton","Roger","Leofrick","Joseph","Geoffrey","William","Francis","Simon","John","Edmund","Charles","Benedict","Gregory","Peter","Henry"
data "Frederick","Thomas","Arthur","Bryce","Donald","Letholdus","Lief","Barda","Rulf","Robin","Gavin","Terryn","Ronald","Jarin","Cassius","Leo"
data "Cedric","Gavin","Peyton","Doran","Asher","Quinn","Xalvador","Favian","Destrian","Berinon"
rem surnames
maxsurname = 46
data "Adeney","Alevi","Ansgot","Aschuill","Aubert","Auvray","Baignard","Baliol","Basnage","Baujot","Bavent","Beaumont","Bele","Belmis","Berners"
data "Bigot","Blosbeville","Boisivon","Boivin","Bondeville","Boneth","Bosanquet","Bossard","Boterel","Bourchier","Bourneville","Braund","Bretel"
data "Brèvedent","Briouse","Buci","Burci","Bursigni","Caen","Cairon","Campion","Caradas","Cardonell","Castillon","Ceauce","Chandos","Cheney"
data "Claville","Coliar","Colombieres","Corbet"
dim firstname$(maxfirstname)
for n = 0 to maxfirstname : read firstname$(n) : next n
dim surname$(maxsurname)
for n = 0 to maxsurname : read surname$(n) : next n
rem --- BIAS TEXT ---
dim recruitbias$(2,3) `// There are three versions of the bias text, each has four lines.
rem neutral
data " has no biases."
data ""
data ""
data ""
rem lawful
data "'s only loyalty is to the law."
data "He does everything by the book,"
data "and is praised well by the"
data "public for doing so."
rem loyal
data " will follow the orders"
data "of those he trusts; even if"
data "those orders are not"
data "strictly legal."
rem read bias text into array
for bias = 0 to 2
for i = 0 to 3
read recruitbias$(bias,i)
next i
next bias
`--
rem -- initialize recruit data --
for n = 1 to 6
recruit(n).firstname = firstname$(rnd(maxfirstname))
recruit(n).surname = surname$(rnd(maxsurname))
recruit(n).lawful = rnd(9)+1
recruit(n).loyal = rnd(9)+1
recruit(n).recruited = 0
recruit(n).portrait = 17 `all recruits currently use the same portrait
next n
return
//
_load_images:
restore _load_images `// this moves the data cursor to here so we don't read the wrong data
set dir "Media/Night Watch/Main Menu/"
data "NightWatchMenuPatrolsHighlighted.bmp","NightWatchMenuCasesHighlighted.bmp","NightWatchMenuFinanceHighlighted.bmp","NightWatchMenuOfficersHighlighted.bmp","NightWatchMenuRecruitmentHighlighted.bmp","NightWatchSubMenu.bmp","Bar/1.bmp","Bar/2.bmp","Bar/3.bmp","Bar/4.bmp","Bar/5.bmp","Bar/6.bmp","Bar/7.bmp","Bar/8.bmp","Bar/9.bmp","Bar/10.bmp","Profile/1.bmp"
restore imageData :`move data cursor to start of image names.
for i = 1 to 17
read imgpath$
if image exist(i) = 0 then load image imgpath$,i
next i
if image exist(21) = 0 then load image "Return Button.bmp",21
return
//
rem ******** FUNCTIONS ********
function mouseInRegion(x1,y1,x2,y2)
`// this structure causes the check to stop as soon as it finds a value out of bounds.
if mousex() >= x1
if mousex() <= x2
if mousey() >= y1
if mousey() <= y2
exitfunction 1
endif
endif
endif
endif
endfunction 0
//
rem [See header notes for an explanation of the silkey function]
function silkey(trigger,oldstate)
newstate = 3&&(oldstate<<1||trigger)
endfunction newstate
//
Formerly OBese87.