simple VB code question-

This forum is meant for requesting technical support or reporting bugs.

Moderators: time-killer-games, Vengeance66, Candle, reneuend, GM-Support

simple VB code question-

Postby Bortdafarm » Sat Jan 28, 2006 9:08 pm

why does this code give the expected end of statement error


Code: Select all
If Dice = 1 Then
Lord Farley = 1
ElseIf Dice = 2 Then
Lady Farley = 1
ElseIf Dice = 3 Then
Bishop Tracepe = 1
ElseIf Dice = 4 Then
Archie Borld = 1
ElseIf Dice = 5 Then
George Cant = 1
ElseIf Dice = 6 Then
Margarie Sene = 1
ElseIf Dice = 7 Then
Cisile Frankes = 1
ElseIf Dice = 8 Then
Billingsgate = 1
ElseIf Dice = 9 Then
Sir Margrete Hill = 1
ElseIf Dice = 10 Then
Advocate senior = 1
Else Dice = 11 Then
Mary Cant = 1
End If


the names shown are variables
Dice is an integrer

all i want to do is roll a dice at game start up

Code: Select all
randomize
Dice = int(rnd*(1-11+1))+1


and set a variable to 1 based on the result--not rocket science you would have thought--been trial and erroring the possible code variations for around 6 hours now and not had one get past the error check--
the help section is of course no help--
code--- i hate it with a passion--- :roll:

just once i'd like to find a help section that was actually aimed at folks who need clear simple step by step instructions and examples--written for folks who need etc etc -see above lol - instead of it being written on the basis that if you can understand and extrapolate the answers from the help section then you don't actually need the help section to start with--

the basic elements of the code is a piece of cake to understand --but it has to be precise and that's where the instructions help and tutorials come in---un fortunately the instructions help and tutorials are impossible to understand any-one got any tutorials written for some-one who actually needs a tutorial?
it's like trying to learn French from a book entirely written in French- if you see my point
Bortdafarm
 

Postby Bortdafarm » Sat Jan 28, 2006 10:36 pm

here's a further example
Code: Select all
If Dice = 1 Then
Lord Farley = 1
ElseIf Dice = 2 Then
Lady Farley = 1
ElseIf Dice = 3 Then
Bishop Tracepe = 1
ElseIf Dice = 4 Then
Archie Borld = 1
ElseIf Dice = 5 Then
George Cant = 1
ElseIf Dice = 6 Then
Margarie Sene = 1
ElseIf Dice = 7 Then
Cisile Frankes = 1
ElseIf Dice = 8 Then
Billingsgate = 1
ElseIf Dice = 9 Then
Sir Margrete Hill = 1
ElseIf Dice = 10 Then
Advocate senior = 1
Else
Mary Cant = 1
End If



expected end of statement error

and a simplified version

Code: Select all
If Dice = 1 Then
Lord Farley = 1
Else If Dice = 2 Then
Lady Farley = 1
Else   
Mary Cant = 1
End If


the above returns an expected "IF" error --- where would you put this celebrated missing IF...?

yet this sample taken from the help pages gives no error--

Code: Select all
If VAR1 < N Then
Action.AddItem "ITEM_NAME"
VAR1 = VAR1 + 1
Else
Message "You cannot carry more than N items."
End If


on what planet am i supposed to be able to make sense of this? :roll:

if i write it like this


Code: Select all
If Dice = 1 Then
Lord Farley = 1
Else   
Lord Farley = 0
End If

If Dice = 2 Then
Lady Farley = 1
Else   
Lady Farley = 0
End If

If Dice = 3 Then
Bishop Tracepe = 1
Else   
Bishop Tracepe = 0
End If

If Dice = 4 Then
Archie Borld = 1
Else   
Archie Borld = 0
End If

If Dice = 5 Then
George Cant = 1
Else   
George Cant = 0
End If

If Dice = 6 Then
Margarie Sene = 1
Else   
Margarie Sene = 0
End If

If Dice = 7 Then
Cisile Frankes = 1
Else   
Cisile Frankes = 0
End If

If Dice = 8 Then
Sir Margrete Hill = 1
Else   
Sir Margrete Hill = 0
End If

If Dice = 9 Then
Billingsgate = 1
Else   
Billingsgate = 0
End If

If Dice = 10 Then
Advocate senior = 1
Else   
Advocate senior = 0
End If

If Dice = 11 Then
Mary Cant = 1
Else   
Mary Cant = 0
End If


i get the expected end of statement error--


but if i reduce the number of entrys to this

Code: Select all
If Dice = 1 Then
Lord Farley = 1
Else   
Lord Farley = 0
End If

If Dice = 2 Then
Lady Farley = 1
Else   
Lady Farley = 0
End If

If Dice = 3 Then
Bishop Tracepe = 1
Else   
Bishop Tracepe = 0
End If

If Dice = 4 Then
Archie Borld = 1
Else   
Archie Borld = 0
End If

If Dice = 5 Then
George Cant = 1
Else   
George Cant = 0
End If

If Dice = 6 Then
Margarie Sene = 1
Else   
Margarie Sene = 0
End If

If Dice = 7 Then
Cisile Frankes = 1
Else   
Cisile Frankes = 0
End If


it accepts it--

am i to assume the error capture facilty in the VB window (enlarged) is purely randomly giving errors cos it don't make much sense--
Last edited by Bortdafarm on Sat Jan 28, 2006 10:58 pm, edited 1 time in total.
Bortdafarm
 

Postby GM-Support » Sat Jan 28, 2006 10:56 pm

Hi,

In VBScript, variables cannot have spaces.

For example, you must replace "Lord Farley" with something like "Lord_Farley".

GM-Support
GM-Support
Forum Admin and Games Page admin
 
Posts: 2221
Joined: Thu Jun 05, 2003 7:52 pm

Postby Bortdafarm » Sat Jan 28, 2006 11:31 pm

argghhh now that's exactly the sort of thing that makes perfect sense only AFTER you find it out (like most of the code stuff lol) many thanks--

ok here's the entire code
with a test to check if it's working which sadly it isn't
Code: Select all
randomize
Dice = int(rnd*(1-11+1))+1

If Dice = 1 Then
Lord_Farley = 1
ElseIf Dice = 2 Then
Lady_Farley = 1
ElseIf Dice = 3 Then
Bishop_Tracepe = 1
ElseIf Dice = 4 Then
Archie_Borld = 1
ElseIf Dice = 5 Then
George_Cant = 1
ElseIf Dice = 6 Then
Margarie_Sene = 1
ElseIf Dice = 7 Then
Cisile_Frankes = 1
ElseIf Dice = 8 Then
Billingsgate = 1
ElseIf Dice = 9 Then
Sir_Margrete_Hill = 1
ElseIf Dice = 10 Then
Advocate_senior = 1
Else
Mary_Cant = 1
End If

If Lord_Farley = 1 Then
Message "Lord Farley."
ElseIf Lady_Farley = 1 Then
Message "Lady Farley."
ElseIf Bishop_Tracepe = 1 Then
Message "Bishop Trancepe."
ElseIf Archie_Borld = 1 Then
Message "Archie Borld."
ElseIf George_Cant = 1 Then
Message "George Cant."
ElseIf Margarie_Sene = 1 Then
Message "Margarie Sene."
ElseIf Cisile_Frankes = 1 Then
Message "Cisile Frankes."
ElseIf Billingsgate = 1 Then
Message "Billingsgate."
ElseIf Sir_Margrete_Hill Then
Message "Sir Margrete Hill."
ElseIf Advocate_senior = 1 Then
Message "Advocate Senior."
Else
Message "Mary Cant."
End If




the Mary Cant message is the only one displayed on screen 100% of the time (after many many tests --randomisation aint what it used to be)

surely the info has had time to be passed to the variables or do i need to create a timed event to hold the message giving the code time to run/ is so how would i cram all that into a timed event code

nope dun work i removed the message section from the code and added it to a hot spot---giving the code time to have run (???) Mary Cant is the only message ever displayed (the default ELSE option in the code in effect)
so the code isn't working no randomisation is taking place at all--

the variables are in GLOBAL --
and so it goes ever on.... :roll:


i've tried the Dice variable as a variant and an integrer to be sure and wrritten the code like this to make sure all the variables are set to 0 before the code runs

Code: Select all
Lord_Farley = 0
Lady_Farley = 0
Bishop_Tracepe = 0
Archie_Borld = 0
George_Cant = 0
Margarie_Sene = 0
Cisile_Frankes = 0
Billingsgate = 0
Sir_Margrete_Hill = 0
Advocate_senior = 0
Mary_Cant = 0

randomize
Dice = int(rnd*(1-11+1))+1

If Dice = 1 Then
Lord_Farley = 1
ElseIf Dice = 2 Then
Lady_Farley = 1
ElseIf Dice = 3 Then
Bishop_Tracepe = 1
ElseIf Dice = 4 Then
Archie_Borld = 1
ElseIf Dice = 5 Then
George_Cant = 1
ElseIf Dice = 6 Then
Margarie_Sene = 1
ElseIf Dice = 7 Then
Cisile_Frankes = 1
ElseIf Dice = 8 Then
Billingsgate = 1
ElseIf Dice = 9 Then
Sir_Margrete_Hill = 1
ElseIf Dice = 10 Then
Advocate_senior = 1
Else
Mary_Cant = 1
End If


no randomisation occurs or it is not being passed to the globals or it is not being passed to the message display section (on a hot spot)

Code: Select all
If Lord_Farley = 1 Then
Message "Lord Farley."
ElseIf Lady_Farley = 1 Then
Message "Lady Farley."
ElseIf Bishop_Tracepe = 1 Then
Message "Bishop Trancepe."
ElseIf Archie_Borld = 1 Then
Message "Archie Borld."
ElseIf George_Cant = 1 Then
Message "George Cant."
ElseIf Margarie_Sene = 1 Then
Message "Margarie Sene."
ElseIf Cisile_Frankes = 1 Then
Message "Cisile Frankes."
ElseIf Billingsgate = 1 Then
Message "Billingsgate."
ElseIf Sir_Margrete_Hill Then
Message "Sir Margrete Hill."
ElseIf Advocate_senior = 1 Then
Message "Advocate Senior."
Else
Message "Mary Cant."
End If


i'm not trying to be a clever dick here (i'm trying to write a game) but this is exactly the sort of thing that makes the learning curve so unnecesarily difficult---it will inevitably be something extremely basic and simple (the above code is extremely basic and simple)

but as has been my experience over and over again with all codeing formats getting hold of this simple information is difficult--put it in the help where it belongs --experienced coders know this simple stuff--what goes where --correct format for naming variables-- learners like me shouldn't need to beg for this information nor sit there trail and erroring untill you lose all enjoyment and enthusiasm completely--

why doesn't the above code work?-- it ought to work --it's dead simple--

so's the answer --it's just i can't find the answer anywhere--

and it's exactly the sort of stuff a newbie (like myself) would be trying to use-- simple randomisations-- nothing fancy just a small step up from the non scripted default actions-- and with code work it's that first step up that's the most challenging--

this place needs a VB code forum desperately--if there was a VB forum here i no doubt would have stumbled across the answer contained in the code snippets posted by other folks and or answers given to other newbies asking similar questions--
Bortdafarm
 

Nailed it!!

Postby Bortdafarm » Sun Jan 29, 2006 1:11 am

:D

I HAD THE MAX AND MIN VALUES FOR THE RANDOMISATION REVERSED--

Code: Select all
randomize
Dice = int(rnd*(1-11+1))+1


when it should have been max value(11)first min value(1)second :oops:

Code: Select all
randomize
Dice = int(rnd*(11-1+1))+1


tired i supposed ---missed it-- :cry:

so here it is for future newbie reference

set of variables in the global section (Lord_Farley etc )
representing game characters (or whatever_)

then in this section in the frame VB code window
set all character variables to 0 (switch em off)

then

a dice roll to randomly set one of these variables to 1 (or switch it on if you like)

if dice rolls as 1 switch Lord_Farley on
if dice rolls as 2 switch Lady_Farley on
etc etc

then

a check to see what character was "switched on" or set to 1

if Lord Farley was switched on show his name on screen
or if
Lady Farely was switched on then show her name on screen instead
and so on


Code: Select all
Lord_Farley = 0
Lady_Farley = 0
Bishop_Tracepe = 0
Archie_Borld = 0
George_Cant = 0
Margarie_Sene = 0
Cisile_Frankes = 0
Billingsgate = 0
Sir_Margrete_Hill = 0
Advocate_senior = 0
Mary_Cant = 0

randomize
Dice = int(rnd*(11-1+1))+1

If Dice = 1 Then
Lord_Farley = 1
ElseIf Dice = 2 Then
Lady_Farley = 1
ElseIf Dice = 3 Then
Bishop_Tracepe = 1
ElseIf Dice = 4 Then
Archie_Borld = 1
ElseIf Dice = 5 Then
George_Cant = 1
ElseIf Dice = 6 Then
Margarie_Sene = 1
ElseIf Dice = 7 Then
Cisile_Frankes = 1
ElseIf Dice = 8 Then
Billingsgate = 1
ElseIf Dice = 9 Then
Sir_Margrete_Hill = 1
ElseIf Dice = 10 Then
Advocate_senior = 1
ElseIf Dice = 11 Then
Mary_Cant = 1
Else
Message "NILL."
End If

If Lord_Farley = 1 Then
Message "Lord Farley."
ElseIf Lady_Farley = 1 Then
Message "Lady Farley."
ElseIf Bishop_Tracepe = 1 Then
Message "Bishop Trancepe."
ElseIf Archie_Borld = 1 Then
Message "Archie Borld."
ElseIf George_Cant = 1 Then
Message "George Cant."
ElseIf Margarie_Sene = 1 Then
Message "Margarie Sene."
ElseIf Cisile_Frankes = 1 Then
Message "Cisile Frankes."
ElseIf Billingsgate = 1 Then
Message "Billingsgate."
ElseIf Sir_Margrete_Hill Then
Message "Sir Margrete Hill."
ElseIf Advocate_senior = 1 Then
Message "Advocate Senior."
ElseIf Mary_Cant = 1 Then
Message "Mary Cant."
Else
Message "all variables nil."
End If




the show message can be replaced with

action.GoToFrame "Frame1"

Code: Select all
If Lord_Farley = 1 Then
action.GoToFrame "Frame1"


or any of the many other possibilitys avialable

there you go---i have a tool which i can use for hundreds of different purposes over and over again

NOTES

variables need to named if more than one word like this

Lord_Farley

(cheers GM!!)

check the custom entrys on code such as the randomisation min max values.. i assume i would go min to max it in fact went max to min--


i've done some whining here to-day but i've provided a tutorial at the end of it so all's well -- :D :idea:
Bortdafarm
 


Return to Adventure Maker Technical Support and Bug Reports

Who is online

Users browsing this forum: No registered users and 0 guests

cron